问题
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.
回答1:
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.)
回答2:
From that same trait, std::ascii::StrAsciiExt.to_ascii_upper and std::ascii::StrAsciiExt.to_ascii_lower are also very handy.
来源:https://stackoverflow.com/questions/19966180/converting-strings-to-lowercase