Archive: Problem with Trim Function


Problem with Trim Function
Hello all.

I'm trying to trim a variable call $Output, that contains a string, that ends with a bunch of \r\n commands like this: "Bla bla bla \r\n \r\n \r\n \r\n \r\n "

Depending on the conditions, there may be lots of these \r\n commands. The $Output variable is being sent into a Text box control within a custom page, that’s why I have to use the \r\n instead of $\r$\n.

I have tried adding the below lines (;added) to the Trim function (both TrimRight and TrimLeft parts) from the archive, but it did not help.

Loop2:
StrCpy $R2 "$R1" 1 -1
StrCmp "$R2" " " TrimRight
StrCmp "$R2" "$\r" TrimRight
StrCmp "$R2" "$\n" TrimRight
StrCmp "$R2" "\r" TrimRight ;added
StrCmp "$R2" "\n" TrimRight ;added
StrCmp "$R2" " " TrimRight ; this is a tab
GoTo Done

Any thoughts would be appreciated. Thanks!


The trimming functions you've tried to modify check one character at a time. You can use StrIOToNSIS to convert to a normal NSIS string and then use TrimNewLines, or you can use StrRep. Both functions are available in StrFunc.nsh. See Examples\StrFunc.nsi for examples.


Thanks much kichik. I added the following, and i'm all set.

${StrRep} $0 "$Output" "\r\n" "$\r$\n"
Push $0
Call Trim
Pop $0
${StrRep} $1 $0 "$\r$\n" "\r\n"
StrCpy $Output $1