知识卡片
字符分类与可失败转换
char 自带 Unicode 字符分类,例如 'β'.is_alphabetic()。按进制解释字符可用 '1'.to_digit(10) 得到 Some(1)。从整数码点或给定进制与数字反推字符时,可以用 char::from_u32 或 char::from_digit,以 Option 体现可能无有效结果。要知道某标量编码后的字节数,可以用 len_utf8()。
关联阅读:[[文本字节数与标量数]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Fundamental Types 比较文本与识别字符 · 查看原书依据
Characters have some methods of their own, for classification and conversions. They are documented under “Primitive Type char”
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|比较文本与识别字符,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#using-strings`
- 结论依据:原文并列举出字符分类、码点转换、编码长度和按进制解析示例,其转换断言使用 Option 包装成功结果。
- 原始内容:Characters have some methods of their own, for classification and conversions. They are documented under “Primitive Type char”