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 aString
variable calledmy_string
and assigns it the value"hello world"
.let uppercase_string = my_string.to_uppercase();
: This line calls theto_uppercase()
method on themy_string
variable and assigns the result to a newString
variable calleduppercase_string
.
Helpful links
More of Rust
- How to match a URL with a regex in Rust?
- How to replace a capture group using Rust regex?
- How to clear a Rust HashMap?
- Yield example in Rust
- Example of yield_now in Rust?
- How to convert a Rust slice to a fixed array?
- How to use regex to match a group in Rust?
- How to convert a Rust HashMap to a BTreeMap?
- How to yield a thread in Rust?
- How to replace strings using Rust regex?
See more codes...