用工小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12 lines
259 B

7 months ago
  1. export function getStrBytesCount(str) {
  2. let bytesCount = 0;
  3. for (let i = 0; i < str.length; i++) {
  4. const c = str.charAt(i);
  5. if (/^[\u00-\uff]$/.test(c)) {
  6. bytesCount += 1;
  7. } else {
  8. bytesCount += 2;
  9. }
  10. }
  11. return bytesCount;
  12. }