Converting strings to lowercase

青春壹個敷衍的年華 提交于 2019-12-10 18:54:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!