Announcement

Collapse
No announcement yet.

How to remove trailing slash

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to remove trailing slash

    How would one remove a trailing \ from a variable's last position? If this was C++, I'd just check if the last character was a \ and remove it...

    I tried using WordReplace:
    code:

    ${WordReplace} "$R0" "\" "" "E-1" $R1

    The problem I'm running into, is that if a variable holds just C:\, then it works fine (spits out C:). If the variable holds C:\Inetpub\wwwroot, it'll spit out C:\Inetpubwwwroot.

  • #2
    code:
    ${WordReplace} "$R0" "\" "" "E}" $R1
    my functions

    Comment


    • #3
      That seems to work great. Knew I must've been missing something simple...

      Comment


      • #4
        ${WordReplace} is pretty heavy solution for this problem. This simple code will do the same thing.

        ; $R0 = your path

        StrCpy $R1 "$R0" "" -1 ; this gets the last char
        StrCmp $R1 "\" 0 +2 ; check if last char is '\'
        StrCpy $R0 "$R0" -1 ; last char was '\', remove it

        Comment

        Working...
        X