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_stringand assigns it the value of the string"hello world".let uppercase_string = my_string.to_uppercase();: This line calls theto_uppercase()method on themy_stringvariable, and assigns the result to theuppercase_stringvariable.println!("{}", uppercase_string);: This line prints the value of theuppercase_stringvariable to the console.
Helpful links:
More of Rust
- How to match a URL with a regex in Rust?
- How to use Unicode in a regex in Rust?
- How to ignore case in Rust regex?
- How to use regex to match a double quote in Rust?
- Hashshet example in Rust
- How to add an entry to a Rust HashMap?
- How to create a HashMap of structs in Rust?
- Enum as u8 in Rust
- How to replace a capture group using Rust regex?
- How to replace strings using Rust regex?
See more codes...