Afrow UK
19th March 2003 21:04 UTC
Need to get the last bit of a string
I have a path entered by the user which may be:
C:\quake2\baseq2\maps\gbrdday1.map
How can I get the gbrdday1.map bit.
Note that it could be anything, not at all gbrdday1.map
Basicly, the bit after the last \ is what I want.
-Stuart
kichik
19th March 2003 21:09 UTC
You can tweak GetParent to do the trick. And if you don't want to handle the code too much you can get the length of the returned string and trim up to that point using StrCpy with a negative maxlen.
Afrow UK
20th March 2003 21:58 UTC
Here is the script:
I'm not sure how to return it to Exch, Pop and Pushing the variables around, so I've left it as this.
KiCHiK, please show me what the basec Pop, Push and Exch cmds should be.
Usage:
StrCpy $R0 C:\Geoffrey\Freddy
Call GetFileName
DetailPrint $R3 # $R3 is now Freddy
Function GetFileName
StrCpy $R1 -1
loop:
StrCmp $0 1 +2
IntOp $0 $0 + 1
StrCpy $R2 $R0 1 $R1
StrCmp $R2 "" exit
StrCmp $R2 "\" exit
StrCpy $R3 $R2$R3
IntOp $R1 $R1 - 1
Goto loop
exit:
FunctionEnd
Thanks
-Stuart
kichik
20th March 2003 22:58 UTC
Haven't tested it but it should work:
GetFileName
Exch$0 ; input string
Push$1
Push$2
StrCpy$1 0
loop:
IntOp $1 $1 - 1
StrCpy$2 $0 1 $1
StrCmp$2 "" exit_dec
StrCmp$2 "\" exit
Goto loop
exit_dec:
IntOp $1 $1 - 1
exit:
IntOp $1 $1 + 1
StrCpy $0 $0 "" $1
Pop $2
Pop $1
Exch $0
FunctionEnd
>