To convert a string to uppercase in Rust, you can use the to_uppercase()
method of the String class.
In this example,
str1
with a value of "Hello World"
.to_uppercase()
method on str1
to convert it to uppercase.str1
.fn main() {
let str1 = String::from("Hello World");
let upper_case_str1 = str1.to_uppercase();
println!("Uppercase of given string is: {:?}", upper_case_str1);
}
Uppercase of given string is: "HELLO WORLD"
In this example,
str2
with a value of "apple"
.to_uppercase()
method on str2
to convert it to uppercase.str2
.fn main() {
let str2 = String::from("apple");
let upper_case_str2 = str2.to_uppercase();
println!("Uppercase of given string is: {:?}", upper_case_str2);
}
Uppercase of given string is: "APPLE"
In this tutorial, we learned How to convert String to Uppercase in Rust language with well detailed examples.