0Pricing
Learn Rust Coding · Lesson

String Methods

Manipulating text.

Working with Text

Rust's str type offers many built-in methods for inspecting and transforming text. These work on both String and &str.

fn main() {
    let s = "Hello, Rust";
    println!("length {}", s.len());
}

Changing Case

Use to_uppercase and to_lowercase to change letter case. They return a new String.

fn main() {
    let s = "Rust";
    println!("{}", s.to_uppercase());
    println!("{}", s.to_lowercase());
}

All lessons in this course

  1. String vs &str
  2. Slices
  3. String Methods
  4. UTF-8 and Chars
← Back to Learn Rust Coding