What is character.is_ascii_uppercase() method in Rust?
Overview
ASCII stands for American Standard Code for Information Interchange. It is a way of encoding a character set used for communication between computers. ASCII is the first among many encodings, which also include such encodings as the UTF-8, ISO-8859-1, etc.
A character is said to be ASCII if it is a number from 0 to 9, a letter from A to Z, or some special character.
We can check if a particular character is an ASCII uppercase character by using the is_ascii_uppercase() method.
Syntax
character.is_ascii_uppercase()
Syntax for is_ascii_uppercase() method
Parameters
character: This is the character we are checking to see if it is an ASCII uppercase character.
Return value
This method returns a boolean value. It returns true when the character is an ASCII uppercase character. Otherwise, it returns false.
Code example
fn main(){// create some characterslet char1 = 'R';let char2 = '❤'; // non ASCIIlet char3 = 'L'; //let char4 = 'a';let char5 = 'U';// check if ASCII uppercase charactersprintln!("{}", char1.is_ascii_uppercase());println!("{}", char2.is_ascii_uppercase());println!("{}", char3.is_ascii_uppercase());println!("{}", char4.is_ascii_uppercase());println!("{}", char5.is_ascii_uppercase());}
Explanation
- Lines 3–7: We create some characters.
- Lines 10–14: We check if the characters are ASCII uppercase characters and print the results to the console.