asp将中文汉字字符转为unicode编码(\u编码)与把unicode编码转为汉字
近期在解析一个json的时候,发现中文被Unicode转换了,显示的是一串Unicode代码,怎么使用asp将中文转换成Unicode的呢,或者将Unicod转换成中文呢<%
dim zhuan_text
zhuan_text = "易做图网 yizuotu.net"
%>
要转换的内容:<%=zhuan_text%><br />
转换之后的代码:<%=tounicode(zhuan_text)%><br />
转码之后的文字:<%=unicodeto("\\u6df1\u5c71\u5de5\u4f5c\u5ba4")%><br />
<%
function tounicode(str) '中文转unicode
tounicode=""
dim i
for i=1 to len(str)
'asc函数:返回字符串的第一个字母对应的ANSI字符代码
'AscW函数:返回每一个GB编码文字的Unicode字符代码
'hex函数:返回表示十六进制数字值的字符串
tounicode=tounicode & "\u" & LCase(Right("0000" & Cstr(hex(AscW(mid(str,i,1)))),4))
next
end function
'\u6613\u505a\u56fe\u7f51 yizuotu.net
function unicodeto(str) 'unicode转中文
str=replace(str,"\u","")
unicodeto=""
dim i
for i=1 to len(str) step 4
'cint函数:将Variant类型强制转换成int类型
'chr函数:返回数值对应的ANSI编码字符
'ChrW函数:返回数值对应的Unicode编码字符
unicodeto=unicodeto & ChrW(cint("&H" & mid(str,i,4)))
next
end function
%>