function stringToByte (str) {
var len, c;
len = str.length;
var bytes = [];
for (var i = 0; i < len; i++) {
c = str.charCodeAt(i);
if (c >= 0x010000 && c <= 0x10FFFF) {
bytes.push(((c >> 18) & 0x07) | 0xF0);
bytes.push(((c >> 12) & 0x3F) | 0x80);
bytes.push(((c >> 6) & 0x3F) | 0x80);
bytes.push((c & 0x3F) | 0x80);
} else if (c >= 0x000800 && c <= 0x00FFFF) {
bytes.push(((c >> 12) & 0x0F) | 0xE0);
bytes.push(((c >> 6) & 0x3F) | 0x80);
bytes.push((c & 0x3F) | 0x80);
} else if (c >= 0x000080 && c <= 0x0007FF) {
bytes.push(((c >> 6) & 0x1F) | 0xC0);
bytes.push((c & 0x3F) | 0x80);
} else {
bytes.push(c & 0xFF);
}
}
return bytes;
}
const r = stringToByte("数据数量限制2000,导出失败!")
console.log(r);
console.log(r.length);
[
230, 149, 176, 230, 141, 174, 230, 149,
176, 233, 135, 143, 233, 153, 144, 229,
136, 182, 50, 48, 48, 48, 239, 188,
140, 229, 175, 188, 229, 135, 186, 229,
164, 177, 232, 180, 165, 239, 188, 129
]
40