asp将中文汉字字符转为unicode编码(\u编码)与把unicode编码转为汉字
网络 2019/4/16 11:19:50 深山行者 字体:
大 中 小 浏览 10233
<%
dim zhuan_text
zhuan_text = "深山工作室"
%>
要转换的内容:<%=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
'\u6df1\u5c71\u5de5\u4f5c\u5ba4
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
%>
- 相关阅读
- 层展开/关闭 - 运动缓冲效果
- ASP读取ACCSS数据代码
- 超级强的div+css点击变样式菜单,特别推荐
- 利用ASP正则查找文章里面的图片,然后在新窗口打开
- asp简易论坛教程(一)——简易论坛系统制作说明图
- 仿百度知道宽度高度自适应的圆角边框
- Asp.net中防止用户多次登录的方法
- ASP汉字图片验证码
- 共有0条关于《asp将中文汉字字符转为unicode编码(\u编码)与把unicode编码转为汉字》的评论
- 发表评论