将字符串转换为小写 [英] Converting strings to lowercase

查看:81
本文介绍了将字符串转换为小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将字符串转换为小写或忽略大小写进行等效性比较?在 Ascii 类型上有一个忽略的情况,但是它看起来很复杂,我看不到转换 str 的方法。到 Ascii

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.

推荐答案

std :: ascii :: AsciiExt.eq_ignore_ascii_case 做您想做的事情:

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

use std::ascii::AsciiExt;

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

(文档中的搜索现在非常好;搜索类似 case和 ascii返回包含此解决方案的良好结果集。)

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

这篇关于将字符串转换为小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆