StrStr: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Added category links.) |
m (Adding new author and category links.) |
||
Line 1: | Line 1: | ||
{ | {{PageAuthor|sunjammer}} | ||
== Description == | == Description == | ||
This function searches for a substring on a string, and returns itself plus the remaining of the string. Doesn't work with Unicode. | This function searches for a substring on a string, and returns itself plus the remaining of the string. Doesn't work with Unicode. | ||
Line 50: | Line 48: | ||
</highlight-nsis> | </highlight-nsis> | ||
[[ | [[Category:String Functions]] |
Revision as of 13:47, 24 June 2005
Author: sunjammer (talk, contrib) |
Description
This function searches for a substring on a string, and returns itself plus the remaining of the string. Doesn't work with Unicode.
The Function
; 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 loop: StrCpy $R5 $R2 $R3 $R4 StrCmp $R5 $R1 done StrCmp $R5 "" done IntOp $R4 $R4 + 1 Goto loop done: StrCpy $R1 $R2 "" $R4 Pop $R5 Pop $R4 Pop $R3 Pop $R2 Exch $R1 FunctionEnd