From 8c2b94e0fd59d7566f9eb89ad83a6c5a93ddf3d6 Mon Sep 17 00:00:00 2001 From: payne-wu Date: Fri, 3 Jan 2025 16:08:32 +0800 Subject: [PATCH] update --- src/utils/typeConversion.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/utils/typeConversion.ts b/src/utils/typeConversion.ts index 01baea8..e83d5b4 100644 --- a/src/utils/typeConversion.ts +++ b/src/utils/typeConversion.ts @@ -6,11 +6,15 @@ * @param {[]} utf8Bytes * @returns {string} */ +// export // byte[]转string +// 完美解决中文乱码的问题 +// 网上的常规思路是将数组变为16进制字符串,然后再每两位转化成字符,这样会带来中文乱码的问题 + export function utf8ByteToUnicodeStr(utf8Bytes: []) { - let unicodeStr = ''; - for (let pos = 0; pos < utf8Bytes.length;) { - let flag = utf8Bytes[pos]; - let unicode = 0; + var unicodeStr = ''; + for (var pos = 0; pos < utf8Bytes.length;) { + var flag = utf8Bytes[pos]; + var unicode = 0; if ((flag >>> 7) === 0) { unicodeStr += String.fromCharCode(utf8Bytes[pos]); pos += 1;