香 As you can see, the value is...">

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 is the following Chinese character: 香

So far so good. I have a VBScript that reads the value of this particular switch and stores it in a variable. When I display the contents using the message box, a Chinese character appears. In addition, I have a variable called uniVal, where I directly assign the unicode of the Chinese character:

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

Is it possible to read the value of the camera so that the Unicode string is saved and is NOT interpreted as a Chinese character?

Of course, I could try to recreate the unicode of the character, but the methods that I found in VBScript do not work correctly due to the implicit UTF-16 VBScripts (instead of UTF-8). Thus, 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

Greetings Chris

+3
source share
2 answers

I have a solution:

JavaScript has a function that really 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 ... :)

+2
source

Here is a VBScript function that will always return a positive value for the Unicode code point of a given character: -

Function PositiveUnicode(s)

    Dim val : val = AscW(s)
    If (val And &h8000) <> 0 Then
        PositiveUnicode = (val And &h7FFF) + &h8000& 
    Else
        PositiveUnicode = CLng(val)
    End If

End Function

This will allow you to load two script engines to perform a simple operation.

"does not work properly due to implicit UTF-16 VBScripts (instead of UTF-8).

UTF-8. AscW .

& #xxxxx; , , HTML ( XML). , . , DOM .

+1

Source: https://habr.com/ru/post/1723198/


All Articles