<script>
function NativeConvertAscii(str) {
var nativecode = str.split("");
var ascii = "";
for (var i = 0; i < nativecode.length; i++) {
var code = Number(nativecode[i].charCodeAt(0));
if (code > 127) {
var charAscii = code.toString(16);
charAscii = new String("0000").substring(charAscii.length, 4) + charAscii;
ascii += "\\u" + charAscii;
} else {
ascii += nativecode[i];
}
}
document.write(ascii);
}
</script>
<script>NativeConvertAscii("中国")</script>
输出\u4e2d\u56fd
用ASP代码如何实现以上js实现的效果啊?
------解决方案--------------------
你看下这样对吧
Function NativeConvertAscii(str)
dim i,s,c,a
s=""
For i=1 to Len(str)
c=Mid(str,i,1)
a=ASCW(c)
If a>127 or a <0 Then
s = s & "\u" & right("00"& Hex(a),4)
Else
s=s & c
End If
Next
NativeConvertAscii= s
End Function