Skip to content
⌘ NSIS Forum Archive

Trimming spaces

3 posts

thelliez#

Trimming spaces

Ok, before I reinvent the wheel, has someone written some code to trim spaces on both sides of a string?

' xyz abc ' -> 'xyz abc'


Thanks,
Thierry
Instructor#
Name "Output"
OutFile "Output.exe"

!include "WordFunc.nsh"
!insertmacro WordReplace

Section
${WordReplace} " xyz abc " " " "" "{}" $R0
# $R0="xyz abc"

MessageBox MB_OK '$$0={$0}'
SectionEnd
iceman_k#
Or, use this function. It will trim all leading and trailing whitespaces (including tabs, CR and LF).
Usage:

Push ' xyz abc '
Call Trim
Pop $0 ;$0 now contains the trimmed string.