查看: 234|回复: 0

[ASP函数] asp将中文汉字字符转为unicode编码与unicode编码转为汉字

[复制链接]
xuanxiao 发表于 2022-11-20 15:03:43 | 显示全部楼层 |阅读模式
要转换的内容:<%=zhuan_text%>
转换之后的代码:<%=tounicode(zhuan_text)%>
转码之后的文字:<%=unicodeto("\\u6df1\u5c71\u5de5\u4f5c\u5ba4")%>

  1. <%
  2. function tounicode(str) '中文转unicode
  3. tounicode=""
  4. dim i
  5. for i=1 to len(str)
  6. 'asc函数:返回字符串的第一个字母对应的ANSI字符代码
  7. 'AscW函数:返回每一个GB编码文字的Unicode字符代码
  8. 'hex函数:返回表示十六进制数字值的字符串
  9. tounicode=tounicode & "\u" & LCase(Right("0000" & Cstr(hex(AscW(mid(str,i,1)))),4))
  10. next
  11. end function

  12. '\u6df1\u5c71\u5de5\u4f5c\u5ba4
  13. function unicodeto(str) 'unicode转中文
  14. str=replace(str,"\u","")
  15. unicodeto=""
  16. dim i
  17. for i=1 to len(str) step 4
  18. 'cint函数:将Variant类型强制转换成int类型
  19. 'chr函数:返回数值对应的ANSI编码字符
  20. 'ChrW函数:返回数值对应的Unicode编码字符
  21. unicodeto=unicodeto & ChrW(cint("&H" & mid(str,i,4)))
  22. next
  23. end function
  24. %>
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表

在线客服

售前咨询
售后咨询
服务热线
023-58418553
微信公众号