123456export function strToUTF16(str: string): any {7 let buf: number[] = [];8 for (let i=0, strLen=str.length; i < strLen; i++) {9 buf.push(str.charCodeAt(i));10 }11 return buf;12}1314export function utf16ToStr(buf: number[]): string {15 let str: string = "";16 for (let i=0, strLen=buf.length; i < strLen; i++) {17 if (buf[i] != 0) str += String.fromCharCode(buf[i]);18 else break;19 }20 return str;21}2223export function hexToStr(buf: string): string {24 let str: string = "";25 let hexStart = buf.indexOf("0x");26 if (hexStart < 0) hexStart = 0;27 else hexStart = 2; 28 for (let i=hexStart, strLen=buf.length; i < strLen; i+=2) {29 let ch = buf[i] + buf[i+1];30 let num = parseInt(ch, 16);31 if (num != 0) str += String.fromCharCode(num);32 else break;33 }34 return str;35}