Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode, VBScript and HTML

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

like image 262
Chris Avatar asked Sep 02 '26 12:09

Chris


1 Answers

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... :)

like image 164
Chris Avatar answered Sep 04 '26 03:09

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!