rustHow to uppercase a string in Rust
You can uppercase a string in Rust using the to_uppercase()
method. Here is an example:
let my_string = "hello world";
let uppercase_string = my_string.to_uppercase();
println!("{}", uppercase_string);
Output
HELLO WORLD
Explanation:
let my_string = "hello world";
: This line declares a variablemy_string
and assigns it the value of the string"hello world"
.let uppercase_string = my_string.to_uppercase();
: This line calls theto_uppercase()
method on themy_string
variable, and assigns the result to theuppercase_string
variable.println!("{}", uppercase_string);
: This line prints the value of theuppercase_string
variable to the console.
Helpful links:
More of Rust
- How to escape dots with regex in Rust?
- How to use regex to match a double quote in Rust?
- How to replace a capture group using Rust regex?
- How to replace strings using Rust regex?
- How to use regex with bytes in Rust?
- How to perform matrix operations in Rust?
- How to parse JSON string in Rust?
- How to get an entry from a HashSet in Rust?
- How to use non-capturing groups in Rust regex?
- How to implement PartialEq for a Rust HashMap?
See more codes...