Get last part and rest of string: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
No edit summary |
|||
Line 25: | Line 25: | ||
Push $R3 | Push $R3 | ||
Push $R4 | Push $R4 | ||
StrCpy $R2 | StrCpy $R2 -1 | ||
StrLen $R4 $R0 | StrLen $R4 $R0 | ||
Loop: | Loop: | ||
IntOp $R2 $R2 | IntOp $R2 $R2 + 1 | ||
StrCpy $R3 $R0 1 $R2 | StrCpy $R3 $R0 1 $R2 | ||
StrCmp $R3 $R1 Chop | StrCmp $R3 $R1 Chop | ||
StrCmp $R2 | StrCmp $R2 $R4 0 Loop | ||
StrCpy $R0 "" | StrCpy $R0 "" | ||
StrCpy $R1 "" | StrCpy $R1 "" | ||
Goto Done | Goto Done | ||
Chop: | Chop: | ||
StrCpy $R1 $R0 $R2 | StrCpy $R1 $R0 -$R2 | ||
IntOp $R2 $R2 | IntOp $R2 $R2 - 1 | ||
StrCpy $R0 $R0 "" $R2 | StrCpy $R0 $R0 "" -$R2 | ||
Done: | Done: | ||
Pop $R4 | Pop $R4 | ||
Pop $R3 | Pop $R3 |
Revision as of 12:35, 14 July 2007
This function has a bug, if it is fed an empty input string it goes into an infinite loop.
Author: Afrow UK (talk, contrib) |
Description
This function returns the last part of a string after a certain character and the rest of the string before that character. If the character is not found within the string, then the function returns two empty strings.
Usage
Push " " ; divider char Push "hello my" ; input string Call GetLastPart Pop $R1 ; last part "my" Pop $R0 ; first part "hello"
The Function
Function GetLastPart Exch $R0 ; input Exch Exch $R1 ; character Push $R2 Push $R3 Push $R4 StrCpy $R2 -1 StrLen $R4 $R0 Loop: IntOp $R2 $R2 + 1 StrCpy $R3 $R0 1 $R2 StrCmp $R3 $R1 Chop StrCmp $R2 $R4 0 Loop StrCpy $R0 "" StrCpy $R1 "" Goto Done Chop: StrCpy $R1 $R0 -$R2 IntOp $R2 $R2 - 1 StrCpy $R0 $R0 "" -$R2 Done: Pop $R4 Pop $R3 Pop $R2 Exch $R1 ; before Exch Exch $R0 ; after FunctionEnd