With the is_ascii_digit()
character method, we can check if a character is an ASCII decimal digit in Rust. A digit is any number from 0 to 9.
character.is_ascii_digit()
character
: This is the character we want to check if it is an ASCII digit.
The value returned is a boolean. If the character is an ASCII digit, a true
will be returned.
fn main(){// check if some characters are really digits in some radixprintln!("{}", 'a'.is_ascii_digit()); // falseprintln!("{}", '1'.is_ascii_digit()); // trueprintln!("{}", '1'.is_ascii_digit()); // trueprintln!("{}", 'c'.is_ascii_digit()); // falseprintln!("{}", 'f'.is_ascii_digit()); // falseprintln!("{}", 'f'.is_ascii_digit()); // false}
is_ascii_digit()
method and then we print the results to the console.