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 variablesand assigns it the value"hello world".let uppercase = s.to_uppercase(): This line calls theto_uppercase()method on thesstring variable, and assigns the result to theuppercasevariable.println!("{}", uppercase): This line prints the value of theuppercasevariable to the console.
Helpful links
More of Rust
- How to replace a capture group using Rust regex?
- How to replace strings using Rust regex?
- How to match whitespace with a regex in Rust?
- How to match a URL with a regex in Rust?
- How to ignore case in Rust regex?
- How to check if a Rust HashMap contains a key?
- Generator example in Rust
- How to convert a Rust slice of u8 to a string?
- Example of struct private field in Rust
- Example of yield_now in Rust?
See more codes...