|
|
#2 |
|
Junior Member
Join Date: Feb 2006
Posts: 11
|
There is a handy function in the User Manual (Appendix C) called StrStr which can be used to find the first occurance of a string. See example
Section "" Push "this is a string with foobar in it" Push "foobar" Call StrStr Pop $R0 StrCpy $R0 $R0 6 ; truncate string to first 6 chrs StrCmp "foobar" $R0 true false ;compare strings true: DetailPrint "foobar is present" Goto End false: DetailPrint "foobar is not present" Goto End End: SectionEnd ; StrStr ; input, top of stack = string to search for ; top of stack-1 = string to search in ; output, top of stack (replaces with the portion of the string remaining) ; modifies no other variables. ; ; Usage: ; Push "this is a long ass string" ; Push "ass" ; Call StrStr ; Pop $R0 ; ($R0 at this point is "ass string") Function StrStr Exch $R1 ; st=haystack,old$R1, $R1=needle Exch ; st=old$R1,haystack Exch $R2 ; st=old$R1,old$R2, $R2=haystack Push $R3 Push $R4 Push $R5 StrLen $R3 $R1 StrCpy $R4 0 ; $R1=needle ; $R2=haystack ; $R3=len(needle) ; $R4=cnt ; $R5=tmp loop99: StrCpy $R5 $R2 $R3 $R4 StrCmp $R5 $R1 done99 StrCmp $R5 "" done99 IntOp $R4 $R4 + 1 Goto loop99 done99: StrCpy $R1 $R2 "" $R4 Pop $R5 Pop $R4 Pop $R3 Pop $R2 Exch $R1 FunctionEnd |
|
|
|
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|