日期:2014-05-16  浏览次数:20346 次

问题不难,就是不会,你说郁闷不?
使用javascript汉字转换成一个16进制数,例如:将汉字 "中 "转换成 "0xD6D0 ".
"中 "字,U+4E2D是它的unicode编码,那0xD6D0是什么啊?



------解决方案--------------------
这是我找的unicode转码的函数,不知道对你有没有用

<SCRIPT language= "VBScript "> <!--
Function URLEncoding(vstrIn)
strReturn = " "
For i = 1 To Len(vstrIn)
ThisChr = Mid(vStrIn,i,1)
If Abs(Asc(ThisChr)) < &HFF Then
strReturn = strReturn & ThisChr
Else
innerCode = Asc(ThisChr)
If innerCode < 0 Then
innerCode = innerCode + &H10000
End If
Hight8 = (innerCode And &HFF00)\ &HFF
Low8 = innerCode And &HFF
strReturn = strReturn & "% " & Hex(Hight8) & "% " & Hex(Low8)
End If
Next
URLEncoding = strReturn
End Function

Function bytes2BSTR(arrBytes)
strReturn = " "
arrBytes = CStr(arrBytes)
For i = 1 To LenB(arrBytes)
ThisCharCode = AscB(MidB(arrBytes, i, 1))
//MsgBox(ThisCharCode)
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
//i = i + 1
//MsgBox(1111)
Else
NextCharCode = AscB(MidB(arrBytes, i+1, 1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
//MsgBox(strReturn)
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
//MsgBox(bytes2BSTR( "test "))
-->
</SCRIPT>
------解决方案--------------------
加前缀“0x”(零和x|X)表示 16 进制整型值。可以包含数字 0 到 9,以及字母 A 到 F(大写或小写)。使用字母 A 到 F 表示十进制 10 到 15 的单个数字。就是说 0xF 与 15 相等,同时 0x10 等于 16。
JS参考手册:http://download.csdn.net/source/204354

------解决方案--------------------
0xD6D0 这个看着象是 gb2312 的区位码
------解决方案--------------------
应该是内码...ANSI编码...
------解决方案--------------------
.......这不是难不难的问题...
而是JS没有这个功能.....