We can check if a character is an ASCII hexadecimal digit in Rust using the is_ascii_hexdigit()
method. A hexadecimal digit is a typical digit of the base-16 number system.
character.is_hexdigit()
character
: This is the character we want to check if it is an ASCII hexadecimal digit.
The value returned is a boolean value.
fn main() {// check if some characters are ASCII hexadecimal digitsprintln!("{}", 'i'.is_ascii_hexdigit());println!("{}", ','.is_ascii_hexdigit());println!("{}", '0'.is_ascii_hexdigit());println!("{}", 'c'.is_ascii_hexdigit());println!("{}", 'f'.is_ascii_hexdigit());println!("{}", 'i'.is_ascii_hexdigit());}
is_ascii_hexdigit()
method. Then we print the results to the console.