Converting strings to lowercase

2019-07-07 01:27发布

How does one convert a string to a lowercase or perform some kind of equivalency comparison ignoring case? There is an ignore case on the Ascii type but it seems convoluted and I don't see a way to convert str to Ascii.

2条回答
孤傲高冷的网名
2楼-- · 2019-07-07 02:04

From that same trait, std::ascii::StrAsciiExt.to_ascii_upper and std::ascii::StrAsciiExt.to_ascii_lower are also very handy.

查看更多
Summer. ? 凉城
3楼-- · 2019-07-07 02:20

std::ascii::AsciiExt.eq_ignore_ascii_case does what you want:

use std::ascii::AsciiExt;

fn main() {
    assert!("foo".eq_ignore_ascii_case("FOO"));
}

(The search in the docs is quite good now; searches like "case" and "ascii" return good sets of results which contain this solution.)

查看更多
登录 后发表回答