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 get a capture group using Rust regex?
- How to use Unicode in a regex in Rust?
- How to get the last element of a Rust slice?
- How to match the end of a line in a Rust regex?
- How to replace a capture group using Rust regex?
- How to use non-capturing groups in Rust regex?
- How to use an enum in a Rust HashMap?
- How to match whitespace with a regex in Rust?
- How to split a string with Rust regex?
- How to match a URL with a regex in Rust?
See more codes...