Start learning free

LESSON 69 OF 348 · STRINGS I

Uppercase and Lowercase in Rust in Rust

Lesson

In Rust, you can convert a string to uppercase or lowercase using the built-in .to_uppercase() and .to_lowercase() methods:

let s = "Hello World";

let upper = s.to_uppercase();
// upper == "HELLO WORLD"

let lower = s.to_lowercase();
// lower == "hello world"

.to_uppercase() converts every character to its uppercase form, and .to_lowercase() converts every character to its lowercase form. Both methods return a new String and do not modify the original.


Assignment
Follow the Coding Tutorial and create upper and lower versions of word!


Hint
Use .to_uppercase() for uppercase and .to_lowercase() for lowercase.

STEP 1 OF 2
    Ctrl + Enter to check

    String Upper Lower in Rust

    Keep going with RustAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free