Rust Strings
String is a growable owned string and &str is a borrowed slice. Use push_str, push, len, to_uppercase, contains, replace, trim and split. Strings are UTF-8.
Example
let mut s = String::from("Hello");
s.push_str(", Rust");
println!("{} {} {}", s, s.len(), s.to_uppercase());
println!("{}", s.replace("Rust", "World"));
println!("{:?}", "a,b,c".split(',').collect::<Vec<_>>());Result
Hello, Rust 11 HELLO, RUST Hello, World ["a", "b", "c"]
Exercise
Append text.
s.(" more")
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.