1export function strToUTF16(str: string): any {2 let buf: number[] = [];3 for (let i=0, strLen=str.length; i < strLen; i++) {4 buf.push(str.charCodeAt(i));5 }6 return buf;7}89export function utf16ToStr(buf: number[]): string {10 let str: string = "";11 for (let i=0, strLen=buf.length; i < strLen; i++) {12 if (buf[i] != 0) str += String.fromCharCode(buf[i]);13 else break;14 }15 return str;16}1718export function hexToStr(buf: string): string {19 let str: string = "";20 let hexStart = buf.indexOf("0x");21 if (hexStart < 0) hexStart = 0;22 else hexStart = 2; 23 for (let i=hexStart, strLen=buf.length; i < strLen; i+=2) {24 let ch = buf[i] + buf[i+1];25 let num = parseInt(ch, 16);26 if (num != 0) str += String.fromCharCode(num);27 else break;28 }29 return str;30}