rustHow do you convert a string to lowercase in Rust?
To convert a string to lowercase in Rust, you can use the to_lowercase()
method. This method is part of the String
type and is available in the std::string
module.
Example code
let my_string = "HELLO WORLD";
let my_string_lowercase = my_string.to_lowercase();
println!("{}", my_string_lowercase);
Output example
hello world
Code explanation
let my_string = "HELLO WORLD";
: This line declares a variablemy_string
and assigns it the value of the string"HELLO WORLD"
.let my_string_lowercase = my_string.to_lowercase();
: This line calls theto_lowercase()
method on themy_string
variable, and assigns the result to themy_string_lowercase
variable.println!("{}", my_string_lowercase);
: This line prints the value of themy_string_lowercase
variable to the console.
Helpful links
More of Rust
- How to get a capture group using Rust regex?
- How to use regex with bytes in Rust?
- How to match the end of a line in a Rust regex?
- Hashshet example in Rust
- How to create a new Rust HashMap with values?
- How do I use a variable from another file in Rust?
- How to get the length of a Rust HashMap?
- How to get an element from a HashSet in Rust?
- How to implement PartialEq for a Rust HashMap?
- How to convert the keys of a Rust HashMap to a vector?
See more codes...