现在的位置: 首页 > 综合 > 正文

如何进行文字和unicode相互转换

2012年08月27日 ⁄ 综合 ⁄ 共 391字 ⁄ 字号 评论关闭

 

有时候需要将文字变成Unicode 转义序列

Js版

<script>
test = "你好abc"

str = ""
for( i=0; i<test.length; i++ )
{
 temp = test.charCodeAt(i).toString(16);
 str += "\\u"+ new Array(5-String(temp).length).join("0") +temp;
}
document.write (str)
</script>

vbs版

Function Unicode(str1)
 Dim str,temp
 str = ""
 For i=1 to len(str1) 
  temp = Hex(AscW(Mid(str1,i,1)))
  If  len(temp) < 5 Then temp = right("0000" & temp, 4)
  str = str & "\u" & temp
 Next
 Unicode = str
End Function

 

抱歉!评论已关闭.