Old 19th March 2003, 20:04   #1
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 19th March 2003, 20:09   #2
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
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.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 20th March 2003, 20:58   #3
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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

code:

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
Afrow UK is offline   Reply With Quote
Old 20th March 2003, 21:58   #4
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Haven't tested it but it should work:

PHP Code:
Function GetFileName
  Exch 
$input string
  Push 
$1
  Push 
$2
  StrCpy 
$1 0
  loop
:
    
IntOp $$1
    StrCpy 
$$0 1 $1
    StrCmp 
$"" exit_dec
    StrCmp 
$"\" 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 

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump