微信小程序string字符串转UTF-16,UTF-16转string字符转

  • string字符串转UTF-16

function ToUTF16(str) {

var result = new Array();

var k = 0;

for (var i = 0; i < str.length; i++) {

var j = str[i].charCodeAt(0);

result[k++] = j >> 8;

result[k++] = j & 0xFF;

}

return result;

}

  • UTF-16转string字符转

function hexToString(arr) {

var val = ''

for(var i = 0;i < arr.length;i = i+2){

val += String.fromCharCode((arr[i] * 256) + arr[i+1]);

}

return val;

  • }

你可能感兴趣的:(微信小程序string字符串转UTF-16,UTF-16转string字符转)