Get last part and rest of string: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
Line 5: | Line 5: | ||
'''14th July 2007''': Fixed infinite loop on empty string and changed divider character to divider string. | '''14th July 2007''': Fixed infinite loop on empty string and changed divider character to divider string. | ||
== Bug == | |||
larsm: That function does not work: It don't "Get last part and rest of string" it get first part and rest of string. Input: "aaa\\bbb\\ccc\\ddd" --> Output: "aaa" and "bbb\\ccc\\ddd"! | |||
== Usage == | == Usage == |
Revision as of 22:36, 21 September 2009
Author: Afrow UK (talk, contrib) |
Description
This function returns the parts before and after a sub string in a string. If the sub string is not found within the string then the return values are empty.
14th July 2007: Fixed infinite loop on empty string and changed divider character to divider string.
Bug
larsm: That function does not work: It don't "Get last part and rest of string" it get first part and rest of string. Input: "aaa\\bbb\\ccc\\ddd" --> Output: "aaa" and "bbb\\ccc\\ddd"!
Usage
Push "o " ; divider str Push "hello my" ; input string Call GetLastPart Pop $R1 ; last part "my" Pop $R0 ; first part "hell"
The Function
Function GetLastPart Exch $R0 ; input Exch Exch $R1 ; divider str Push $R2 Push $R3 Push $R4 Push $R5 StrCpy $R2 -1 StrLen $R4 $R0 StrLen $R5 $R1 Loop: IntOp $R2 $R2 + 1 StrCpy $R3 $R0 $R5 $R2 StrCmp $R3 $R1 Chop StrCmp $R2 $R4 0 Loop StrCpy $R0 "" StrCpy $R1 "" Goto Done Chop: StrCpy $R1 $R0 $R2 IntOp $R2 $R2 + $R5 StrCpy $R0 $R0 "" $R2 Done: Pop $R5 Pop $R4 Pop $R3 Pop $R2 Exch $R1 ; before Exch Exch $R0 ; after FunctionEnd