Tsallaka zuwa abun ciki
Justice Tech School

String Methods

contains, replace, to_uppercase, trim, split, starts_with and parse are common.

Example
fn main() {
    let s = "  Hello, Rust  ";
    let t = s.trim();
    println!("{} {} {}", t.to_uppercase(), t.contains("Rust"), t.replace("l", "L"));
    println!("{:?}", "a,b,c".split(',').collect::<Vec<_>>());
    let n: i32 = "42".parse().unwrap();
    println!("{}", n + 1);
}

Result

HELLO, RUST true HeLLo, Rust
["a", "b", "c"]
43

Exercise

Parse text.

"5".::<i32>()

Quiz Test

What does split return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.