【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());
}
总结
了解了字符串切片中相关的一些方法。
附录
标签:name,JiangBo,切片,println,let,fn,字符串,main,Rust 来源: https://www.cnblogs.com/jiangbo4444/p/16322808.html