Remove spaces at both ends
Remove the spaces before and after a name. A space between two words stays in place. These examples use ordinary spaces.
str::trim
Simple example
Trim the single letter.
Start' a '
Resulta
fn main() {
println!("{}", " a ".trim());
}
a
Advertisements
Everyday examples
Remove the extra spaces copied around a ticket number.
Start' B12 '
ResultB12
fn main() {
println!("{}", " B12 ".trim());
}
B12
Clean up the outside spaces on a shelf label.
Start' Red Apples '
ResultRed Apples
fn main() {
println!("{}", " Red Apples ".trim());
}
Red Apples
Clean up a name copied from a signup sheet.
Start' Ana '
ResultAna
fn main() {
println!("{}", " Ana ".trim());
}
Ana