We can check if a character is an ASCII punctuation with the is_ascii_punctuation()
method. ASCII is a form of character encoding which is used in encoding and decoding characters during communication between computers. Other encodings include UTF-8, ISO-8859-1, GBK, ISO-8859-11, and more.
character.is_ascii_punctuation()
character
: This is the character we are checking to see if it is an ASCII punctuation character or not.
The value returned is a Boolean value. We get true
if the character is an ASCII punctuation. Otherwise, false
is returned.
fn main(){// check if some characters are really digits in some radixprintln!("{}", '#'.is_ascii_punctuation()); // trueprintln!("{}", 'š'.is_ascii_punctuation()); // falseprintln!("{}", 'š£'.is_ascii_punctuation()); // falseprintln!("{}", '?'.is_ascii_punctuation()); // trueprintln!("{}", '!'.is_ascii_punctuation()); // trueprintln!("{}", '.'.is_ascii_punctuation()); // true}
is_ascii_punctuation()
method to check if some characters are ASCII punctuation characters. Then we print the results to the console.