Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

rust
hexadecimal
ascii
character
communitycreator

How to check if a character is an ASCII hexadecimal digit in Rust

okwudili onyejiaku

Overview

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.

Syntax

character.is_hexdigit() 
Syntax for character.is_ascii_hexdigit() in Rust

Parameters

character: This is the character we want to check if it is an ASCII hexadecimal digit.

Return value

The value returned is a boolean value.

Example

fn main() {
    // check if some characters are ASCII hexadecimal digits
    println!("{}", '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());
}
Check if some characters are ASCII hexadecimal digits

Explanation

  • Lines 3–8: We check if some characters in Rust were ASCII hexadecimal digits using the is_ascii_hexdigit() method. Then we print the results to the console.

RELATED TAGS

rust
hexadecimal
ascii
character
communitycreator
RELATED COURSES

View all Courses

Keep Exploring