Old 13th March 2012, 16:21   #1
HaMsTeYr
Junior Member
 
Join Date: Feb 2006
Posts: 44
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?
HaMsTeYr is offline   Reply With Quote
Old 13th March 2012, 16:37   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You could use this: http://nsis.sourceforge.net/StrCSpn,...for_characters

Stu
Afrow UK is offline   Reply With Quote
Old 13th March 2012, 16:40   #3
HaMsTeYr
Junior Member
 
Join Date: Feb 2006
Posts: 44
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
HaMsTeYr is offline   Reply With Quote
Old 13th March 2012, 16:56   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 13th March 2012, 19:16   #5
pengyou
Major Dude
 
Join Date: Mar 2003
Posts: 571
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

pengyou is offline   Reply With Quote
Old 13th March 2012, 21:44   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
invalid character delete

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump