- //字符串转换Uint8Array
//字符串转换Uint8Array
stringToUint8Array(str, len=null) {
let arr = [];
if (len == null) {
len = str.length
}
for (let i = 0; i < len; i++) {
if (str.length > i) {
arr.push(str.charCodeAt(i))
} else {
arr.push(0)
}
}
return new Uint8Array(arr);
}
2.转码方法
let that = new util.Base64Helper();
let results = that.encodeToStringSync(this.stringToUint8Array('a87654321', null));
console.info("转码结果:"+results)