知识卡片

普通读书笔记卡 · 10642.f · 生成模型:未记录

折叠大小写后保留原文

理解等级:中级

to_lowercase() 创建新的 String。对查询和待比较行同时小写化,再做子串比较。结果保留原行切片,显示内容不受转换影响。此简化覆盖常见示例,完整 Unicode 大小写无关匹配需要额外处理。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • I/O 项目:构建命令行程序 Working with Environment Variables · 查看原书依据

      First we lowercase the query string and store it in a shadowed variable with the same name ❶. Calling to_lowercase on the query is necessary so that no matter whether the user’s query is "rust", "RUST", "Rust", or "rUsT", we’ll treat the query as if it were "rust" and be insensitive to the case. While to_lowercase will handle basic Unicode, it won’t be 100 percent accurate.

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第12章 I/O 项目:构建命令行程序(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c12.xhtml`,块 0260) - 结论依据:原文解释小写比较的原理,并指出简单 Unicode 转换的准确性边界。 - 原始内容:First we lowercase the query string and store it in a shadowed variable with the same name ❶. Calling to_lowercase on the query is necessary so that no matter whether the user’s query is "rust", "RUST", "Rust", or "rUsT", we’ll treat the query as if it were "rust" and be insensitive to the case. While to_lowercase will handle basic Unicode, it won’t be 100 percent accurate.