rust char uppercase
To convert a char
to uppercase in Rust, you can use the to_uppercase
method provided by the char
type. This method returns a new char
that represents the uppercase version of the original character. Here's an example:
fn main() {
let c: char = 'a';
let uppercase_c = c.to_uppercase();
println!("Uppercase: {}", uppercase_c);
}
This code will output:
Uppercase: A
In this example, we first declare a variable c
of type char
and assign it the value 'a'
. We then call the to_uppercase
method on c
to get the uppercase version of the character, which is assigned to the variable uppercase_c
. Finally, we print the value of uppercase_c
, which will be 'A'
.
Note that the to_uppercase
method returns an iterator over the uppercase characters because some characters may have multiple uppercase representations or may not have an uppercase equivalent. To convert the iterator back to a single char
, you can use the next
method.