Trim
fn main() {
let s = " Hello Rust! ";
// trim移除字符串开始末尾的空格
// "Hello Rust!"
println!("{}", s.trim());
// trim_start移除字符串开始的空格
// "Hello Rust! "
println!("{}", s.trim_start());
// trim_end移除字符串末尾的空格
// " Hello Rust!"
println!("{}", s.trim_end());
let s = "abcabcabcHello Rust!abcabcabc";
// trim_start_matches移除字符串开始匹配的字符串
// "Hello Rust!abcabcabc"
println!("{}", s.trim_start_matches("abc"));
// trim_start_matches移除字符串开始匹配的字符串
// "abcabcabcHello Rust!"
println!("{}", s.trim_end_matches("abc"));
}
标签:trim,处理,start,移除,字符串,println,Rust
From: https://www.cnblogs.com/BuzzWeek/p/16861661.html