一、将汉字转换为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 = ' |
|