【Rust】字符串切片(五)
作者:互联网
环境
- Time 2022-03-24
- Rust 1.59.0
示例
match_indices
fn main() {
let name = "\nJiang\nBo\n";
name.match_indices(char::is_alphabetic)
.for_each(|e| println!("{e:?}"));
}
rmatch_indices
fn main() {
let name = "\nJiang\nBo\n";
name.rmatch_indices(char::is_alphabetic)
.for_each(|e| println!("{e:?}"));
}
trim
fn main() {
let name = "\nJiang\nBo\n";
println!("{:?}", name.trim());
}
trim_start
fn main() {
let name = "\nJiang\nBo\n";
println!("{:?}", name.trim_start());
}
trim_end
fn main() {
let name = "\nJiang\nBo\n";
println!("{:?}", name.trim_end());
}
trim_matches
fn main() {
let name = "\nJiang\nBo\n";
println!("{:?}", name.trim_matches('\n'));
}
trim_start_matches
fn main() {
let name = "\nJiang\nBo\n";
println!("{:?}", name.trim_start_matches('\n'));
}
trim_end_matches
fn main() {
let name = "\nJiang\nBo\n";
println!("{:?}", name.trim_end_matches('\n'));
}
strip_prefix
fn main() {
let name = "\nJiang\nBo\n";
println!("{:?}", name.strip_prefix('\n'));
}
总结
了解了字符串切片中相关的一些方法。
附录
标签:trim,nJiang,name,切片,let,fn,字符串,main,Rust 来源: https://www.cnblogs.com/jiangbo4444/p/16322804.html