Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   Removing invalid characters from a string (http://forums.winamp.com/showthread.php?t=343127)

HaMsTeYr 13th March 2012 16:21

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:
code:
${WordReplace} "$0" "®" "" "+" $0

But that doesn't seem to work.

Any workaround to this?

Afrow UK 13th March 2012 16:37

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

Stu

HaMsTeYr 13th March 2012 16:40

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

Afrow UK 13th March 2012 16:56

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

pengyou 13th March 2012 19:16

Quote:

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

Name "Demo"
OutFile demo.exe

RequestExecutionLevel 
"user"

ShowInstDetails show

!include "WordFunc.nsh"

Section default
  
DetailPrint ""
  
StrCpy $"Application Name Example® v1.0"
  
DetailPrint "Input : $0"
  
${WordReplace"$0" "®" "" "+" $0
  DetailPrint 
"Output: $0"
  
DetailPrint ""
SectionEnd 

Compiled and ran demo.exe and it produced:
code:
Input : Application Name Example® v1.0
Output: Application Name Example v1.0


Afrow UK 13th March 2012 21:44

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


All times are GMT. The time now is 17:33.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.