Archive: Removing invalid characters from a string


Removing invalid characters from a string
  I don't know if I'm not looking hard enough, but I couldn't find a topic on this, so I'm posting it here.

Essentially, in my nsis program I'm running some of the files have strange characters like " ®" or "©". They're problemful for me and I need them removed from the string itself.

So for example, $0 contains:

"Application Name Example® v1.0"

I need it to become:

"Application Name Example v1.0"

I know there are results about removing the more standard 'found on keyboard' invalid characters, but what about ones like these?

I've tried:

${WordReplace} "$0" "®" "" "+" $0

But that doesn't seem to work.

Any workaround to this?

You could use this: http://nsis.sourceforge.net/StrCSpn,...for_characters

Stu


I took a look at that function before hand, and from what I gather, all it does is flag me if the string contains an invalid character, correct me if I'm wrong.

I need to actually remove it from the string though


I think it'd be best to write your own function for this. Iterate through all characters in A and copy to B ignoring any characters that are invalid.

Stu


I've tried:
${WordReplace} "$0" "®" "" "+" $0
But that doesn't seem to work.
It seemed to work for me:

Name "Demo"

>OutFile demo.exe

RequestExecutionLevel "user"

>ShowInstDetails show

>!include "WordFunc.nsh"

>Section default
DetailPrint ""
StrCpy $0 "Application Name Example® v1.0"
DetailPrint "Input : $0"
${WordReplace} "$0" "®" "" "+" $0
DetailPrint "Output: $0"
DetailPrint ""
>SectionEnd
>
Compiled and ran demo.exe and it produced:
Input : Application Name Example® v1.0
Output: Application Name Example v1.0

That method will never do unless you know the complete set of characters you have to remove. It would be simpler, as you say, to only include valid ASCII characters. A custom function is likely needed unless a solution already exists.

Stu