rustHow do I capitalize a string in Rust?
To capitalize a string in Rust, you can use the to_uppercase()
method. This method is available on all String
types.
Example code
let my_string = "hello world";
let my_string_uppercase = my_string.to_uppercase();
Output example
HELLO WORLD
The code above takes a string, my_string
, and calls the to_uppercase()
method on it. This returns a new string, my_string_uppercase
, which is the original string with all characters capitalized.
Parts of the code:
let my_string = "hello world";
: This declares a variable,my_string
, and assigns it the value of the string"hello world"
.let my_string_uppercase = my_string.to_uppercase();
: This calls theto_uppercase()
method on themy_string
variable, and assigns the result to themy_string_uppercase
variable.
Helpful links
More of Rust
- How to get a capture group using Rust regex?
- How to use regex to match a double quote in Rust?
- How to replace a capture group using Rust regex?
- How to use 'or' in Rust regex?
- How to use non-capturing groups in Rust regex?
- How to use regex to match a group in Rust?
- How to replace all matches using Rust regex?
- How to match the end of a line in a Rust regex?
- How to parse JSON string in Rust?
- How to use regex with bytes in Rust?
See more codes...