rustrust string capitalize
Rust strings can be capitalized using the to_uppercase()
method. This method returns a new string with all characters in uppercase.
Example
let s = "hello world";
let uppercase = s.to_uppercase();
println!("{}", uppercase);
Output example
HELLO WORLD
The to_uppercase()
method takes no parameters and is part of the std::string::String
type. It is a mutable method, meaning it changes the string in place.
Code explanation
let s = "hello world"
: This line declares a string variables
and assigns it the value"hello world"
.let uppercase = s.to_uppercase()
: This line calls theto_uppercase()
method on thes
string variable, and assigns the result to theuppercase
variable.println!("{}", uppercase)
: This line prints the value of theuppercase
variable to the console.
Helpful links
More of Rust
- How to match whitespace with a regex in Rust?
- How to match a URL with a regex in Rust?
- How to use non-capturing groups in Rust regex?
- How to use regex to match a group in Rust?
- How to replace a capture group using Rust regex?
- How to replace all matches using Rust regex?
- How to create a slice from a string in Rust?
- How to replace strings using Rust regex?
- Hashshet example in Rust
- How to create a HashSet from a Vec in Rust?
See more codes...