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 use regex to match a double quote in Rust?
- How to replace a capture group using Rust regex?
- Regex example to match multiline string in Rust?
- How to clear a Rust HashMap?
- How to use non-capturing groups in Rust regex?
- Yield example in Rust
- How to perform matrix operations in Rust?
- How to replace strings using Rust regex?
- How to use regex lookbehind in Rust?
- How to convert the keys of a Rust HashMap to a vector?
See more codes...