其他分享
首页 > 其他分享> > 【Rust】字符串切片(六)

【Rust】字符串切片(六)

作者:互联网

环境

示例

strip_suffix

fn main() {
    let name = "\nJiang\nBo\n";
    println!("{:?}", name.strip_suffix('\n'));
}

parse

fn main() {
    let name = "44";
    println!("{:?}", name.parse::<i32>());
}

is_ascii

fn main() {
    let name = "\nJiang\nBo\n";
    println!("{:?}", name.is_ascii());
}

eq_ignore_ascii_case

fn main() {
    let name = "JiangBo";
    println!("{:?}", name.eq_ignore_ascii_case("jiangbo"));
}

make_ascii_uppercase

fn main() {
    let mut name = String::from("JiangBo");
    name.make_ascii_uppercase();
    println!("{:?}", name);
}

make_ascii_lowercase

fn main() {
    let mut name = String::from("JiangBo");
    name.make_ascii_lowercase();
    println!("{:?}", name);
}

escape_debug

fn main() {
    println!("{}", "❤\n!".escape_debug());
}

escape_default

fn main() {
    println!("{}", "❤\n!".escape_default());
}

escape_unicode

fn main() {
    println!("{}", "❤\n!".escape_unicode());
}

总结

了解了字符串切片中相关的一些方法。

附录

标签:name,切片,println,fn,escape,字符串,main,ascii,Rust
来源: https://www.cnblogs.com/jiangbo4444/p/16322806.html