計算字符串的實際長度,雙字節字符(包括漢字在內)長度計2,ASCII字符計1 方法1:使用match: export function getByteLenMatch(data) { let result = 0; for (let s of data) { result += s.match(/[^\\x00-\\xff]/ig) == null ? 1 : 2; } r