计算字符串所占的内存字节数,默认使用 UTF-8 的编码方式计算,也可指定为 UTF-16。
要计算的字符串
编码格式,支持 utf8 和 utf16,默认为 utf8
字节数
0.0.1
byteLen('1') // 1byteLen('1', 'utf-16') // 2byteLen('\u{5f8}') // 2byteLen('\u{5f8}', 'utf-16') // 2byteLen('以') // 3byteLen('以', 'utf-16') // 2byteLen('𪚥') // 4byteLen('𪚥', 'utf-16') // 4 Copy
byteLen('1') // 1byteLen('1', 'utf-16') // 2byteLen('\u{5f8}') // 2byteLen('\u{5f8}', 'utf-16') // 2byteLen('以') // 3byteLen('以', 'utf-16') // 2byteLen('𪚥') // 4byteLen('𪚥', 'utf-16') // 4
计算字符串所占的内存字节数,默认使用 UTF-8 的编码方式计算,也可指定为 UTF-16。