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.
Free plan: 30 tutor messages. Premium is unlimited.