We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
假如,你有一个蒸汽炸锅... 咳咳,不好意思,串台了。
假如,你需要写一个验证规则来限制文章标题和内容的长度,而你的产品又是面向全世界的...
一般我们会选择 UTF-8 来作为字符集,但 UTF-8 字符集一个字符所占的字节数不定 1-4个字节的范围。
因此 UTF-8 字符串的字节数跟实际的文字字符数不见得是相同的,单纯统计字符串的字节数是不准确的。
下面是不同编程语言的字符数统计方法备忘,欢迎补充
两个特殊字符串,供大家尝试
'I❤𠀰' // 3 characters '😹🐶😹🐶' // 4 characters
The text was updated successfully, but these errors were encountered:
// 10 characters \mb_strlen('hello 😹🐶😹🐶', 'UTF-8');
Sorry, something went wrong.
// 10 characters len([]rune("hello 😹🐶😹🐶"))
// 10 characters [...'hello 😹🐶😹🐶'].length;
use unicode_segmentation::UnicodeSegmentation; // 10 characters "hello 😹🐶😹🐶".graphemes(true).count();
No branches or pull requests
背景
假如,你有一个蒸汽炸锅... 咳咳,不好意思,串台了。
假如,你需要写一个验证规则来限制文章标题和内容的长度,而你的产品又是面向全世界的...
一般我们会选择 UTF-8 来作为字符集,但 UTF-8 字符集一个字符所占的字节数不定 1-4个字节的范围。
因此 UTF-8 字符串的字节数跟实际的文字字符数不见得是相同的,单纯统计字符串的字节数是不准确的。
下面是不同编程语言的字符数统计方法备忘,欢迎补充
两个特殊字符串,供大家尝试
The text was updated successfully, but these errors were encountered: