How to convert a character to lowercase in Rust
Overview
We can covert a character to lowercase in Rust by passing the character to to_lowercase() method.
Syntax
character.to_lowercase()
Syntax for converting a character to lowercase in Rust
Parameters
character: This is the character that we want to convert to lowercase.
Return value
The value returned is an lowercase equivalent of the character character.
Example
fn main(){// create some characterslet char1 = 'o';let char2 = 'T';let char3 = 'A';let char4 = 'Z';let char5 = 'x';// Convert to lowercaseprintln!("{}", char1.to_lowercase());println!("{}", char2.to_lowercase());println!("{}", char3.to_lowercase());println!("{}", char4.to_lowercase());println!("{}", char5.to_lowercase());}
Explanation
- Lines 3–7: We create some characters.
- Lines 10–14: We convert the characters to lowercase using the
to_lowercase()method and print the values to the console.