views:

302

answers:

4

Hi all,

I have the following radio box: <input type="radio" value="&#39321;">&#39321;</input>

As you can see, the value is unicode. It represents the following Chinese character: 香

So far so good. I have a VBScript that reads the value of that particular radio button and saves it into a variable. When I display the content with a message box, the Chinese Character appears. Additionally I have a variable called uniVal where I assign the unicode of the Chinese character directly:

radioVal = < read value of radio button >
MsgBox radioVal  ' yields chinese character
uniVal = "&#39321;"
MsgBox uniVal   ' yields unicode representation

Is there a possibility to read the radio box value in such a way that the unicode string is preserved and NOT interpreted as the chinese character?

For sure, I could try to recreate the unicode of the character, but the methods I found in VBScript are not working correctly due to VBScripts implicit UTF-16 setting (instead of UTF-8). So the following method does not work correctly for all characters:

Function StringToUnicode(str)
 result = ""
 For x=1 To Len(str)
  result = result & "&#"&ascw(Mid(str, x, 1))&";"
 Next
 StringToUnicode = result
End Function

Cheers Chris

A: 

Try Server.HTMLEncode(radioVal).

Heinzi
Sorry,I should have been more precise: I use VBScript that is embedded in HTML!
Chris
A: 

Please, see this link: Unicode in VBScript — the AscW() rant

Rubens Farias
thanks,Perhaps I implemented the shifts not correctly, but the return of that method is also interpreted as chinese characters in my case.. but thanks anyway!
Chris
+1  A: 

I got a solution:

JavaScript is in possession of a function that actually works:

function convert(value) {
 var tstr = value;
 var bstr = '';
for(i=0; i<tstr.length; i++) {
if(tstr.charCodeAt(i)>127)
  {
  bstr += '&#' + tstr.charCodeAt(i) + ';';
  }
else
  {
  bstr += tstr.charAt(i);
  } 
}
return bstr; 
}

I call this function from my VBScript... :)

Chris
+1, thanks for sharing the solution you found!
Heinzi
A: 
AnthonyWJones