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 match whitespace with a regex in Rust?
- How to match a URL with a regex in Rust?
- How to replace a capture group using Rust regex?
- How to replace strings using Rust regex?
- How to use negation in Rust regex?
- Regex example to match multiline string in Rust?
- How to ignore case in Rust regex?
- How to match the end of a line in a Rust regex?
- Rust map example
- How to iterate linked list in Rust
See more codes...