【Rust】字符串切片(七)

环境

  • Time 2022-03-24
  • Rust 1.59.0

示例

into_boxed_bytes

fn main() {
    let name = "JiangBo";
    println!("{:?}", name.to_owned().into_boxed_str().into_boxed_bytes());
}

replace

fn main() {
    let name = "JiangBo";
    println!("{:?}", name.replace("gB", "gb"));
}

replacen

fn main() {
    let name = "JiangBo";
    println!("{:?}", name.replacen("gB", "gb", 2));
}

to_lowercase

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

to_uppercase

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

into_string

fn main() {
    let name = "JiangBo";
    println!("{:?}", name.to_owned().into_boxed_str().into_string());
}

repeat

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

to_ascii_uppercase

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

escape_unicode

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

总结

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

附录

posted @ 2022-05-29 07:49  jiangbo4444  阅读(54)  评论(0编辑  收藏  举报