当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust str.to_lowercase用法及代码示例


本文简要介绍rust语言中 str.to_lowercase 的用法。

用法

pub fn to_lowercase(&self) -> String

返回此字符串切片的小写等效项,作为新的 String

'Lowercase' 是根据 Unicode Derived Core Property Lowercase 的条款定义的。

由于某些字符在更改大小写时可以扩展为多个字符,因此该函数返回一个 String ,而不是就地修改参数。

例子

基本用法:

let s = "HELLO";

assert_eq!("hello", s.to_lowercase());

一个棘手的例子,使用 sigma:

let sigma = "Σ";

assert_eq!("σ", sigma.to_lowercase());

// but at the end of a word, it's ς, not σ:
let odysseus = "ὈΔΥΣΣΕΎΣ";

assert_eq!("ὀδυσσεύς", odysseus.to_lowercase());

没有大小写的语言不会改变:

let new_year = "农历新年";

assert_eq!(new_year, new_year.to_lowercase());

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 str.to_lowercase。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。