rustHow do I uppercase a Rust string?
To uppercase a Rust string, you can use the to_uppercase() method. This method is available on all String types.
Example
let my_string = "hello world";
let uppercase_string = my_string.to_uppercase();
Output example
HELLO WORLD
The to_uppercase() method takes no arguments and returns a new String with all characters in uppercase.
Code explanation
let my_string = "hello world";: This line declares aStringvariable calledmy_stringand assigns it the value"hello world".let uppercase_string = my_string.to_uppercase();: This line calls theto_uppercase()method on themy_stringvariable and assigns the result to a newStringvariable calleduppercase_string.
Helpful links
More of Rust
- How to match a URL with a regex in Rust?
- How to slice a hashmap in Rust?
- How to replace a capture group using Rust regex?
- How to create a HashSet from a Range in Rust?
- How to sort a Rust HashMap?
- How to use regex lookbehind in Rust?
- How to get current date in Rust
- How to replace strings using Rust regex?
- How to use regex captures in Rust?
- How to perform matrix operations in Rust?
See more codes...