Archive: remove last character if it is \

remove last character if it is \
i want a code in nsis which can check for last character in a variable. If last character is / then i want to remove it.


If $var is C:\mypath\ then i want output as only C:\mypath

if $var is C:\mypath then output is C:\mypath

You can 'abuse' the EXEDIR variable for that.
See (first code sample)

For a more robust solution see:

Strcpy $0 $var "" -1
Strcmp $0 "\" 0 +2
Strcpy $var $var -1

great solution

Reading posts here about same subject I've got one of the best ways to do that.

Simple copy your var to $outdir them copy it back.

$Outdir have special a treatment to remove the slash on the end of string

Doing like this will solve your problem.

     StrCpy $OUTDIR $var
StrCpy $var $OUTDIR