汉字与Unicode的相互转换

发布时间:2025-12-09 11:54:56 浏览次数:1

一、将汉字转换为Unicode

 1 /* 2  *将汉字转换为Unicode 3  *charCodeAt返回字符串指定位置的字符的Unicode编码(十进制形式),在0-65535之间。 4  * 5  *toString(16) 将一个数字转成十六进制。 6  */ 7 function toUnicode(chineseStr) { 8     if (chineseStr == '') { 9         return 'Please input Chinese Characters';10     }11     let unicodeStr = '';12     for (let i = 0, iLength = chineseStr.length; i < iLength; i++) {13         unicodeStr += '\\u' + chineseStr.charCodeAt(i).toString(16);14     }15     return unicodeStr;16 }17 let s1 = '我是谁',18     s2 = '


汉字转unicode
需要做网站?需要网络推广?欢迎咨询客户经理 13272073477