I have a variable which contains a single char
. I want to convert this char
to upper case. However, the to_uppercase
function returns a rustc_unicode::char::ToUppercase
struct instead of a char
.
Changing between lowercase and uppercase on a smartphone or tablet. On smartphones and tablets, there is no Caps Lock key or Shift key. To uppercase (capitalize) a letter on these devices, press the up arrow on the on-screen keyboard and then the letter you want to be capitalized.
The toupper() function is used to convert lowercase alphabet to uppercase. i.e. If the character passed is a lowercase alphabet then the toupper() function converts a lowercase alphabet to an uppercase alphabet. It is defined in the ctype. h header file.
Java String toUpperCase() Method The toUpperCase() method converts a string to upper case letters.
The toupper() function in C++ converts a given character to uppercase. It is defined in the cctype header file.
ToUppercase
is an Iterator
, that may yield more than one char
. This is necessary, because some Unicode characters consist of multiple "Unicode Scalar Values" (which a Rust char
represents).
A nice example are the so called ligatures. Try this for example (on playground):
let fi_upper: Vec<_> = 'fi'.to_uppercase().collect();
println!("{:?}", fi_upper); // prints: ['F', 'I']
The 'fi' ligature is a single character whose uppercase version consists of two letters/characters.
There are multiple possibilities how to deal with that:
&str
: if your data is actually in string form, use str::to_uppercase
which returns a String
which is easier to work with.std::ascii::AsciiExt::to_ascii_uppercase
which returns just a char
. But it only changes the letters 'a'
to 'z'
and ignores all other characters! String
or Vec
like in the example above. If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With