Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

rust
ascii
communitycreator

What is character.is_ascii_digit() in Rust?

okwudili onyejiaku

Overview

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.

Syntax

character.is_ascii_digit()
Syntax for is_ascii_digit()

Parameters

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

Return value

The value returned is a boolean. If the character is an ASCII digit, a true will be returned.

Example

fn main(){
  // check if some characters are really digits in some radix
    println!("{}", 'a'.is_ascii_digit());  // false
    println!("{}", '1'.is_ascii_digit());   // true
    println!("{}", '1'.is_ascii_digit());   // true
    println!("{}", 'c'.is_ascii_digit());  // false
    println!("{}", 'f'.is_ascii_digit());  // false
    println!("{}", 'f'.is_ascii_digit());  // false
}
Check if a character is ASCII digit in Rust

Explanation

  • Lines 3–8: We check if some characters were ASCII digit characters using the is_ascii_digit() method and then we print the results to the console.

RELATED TAGS

rust
ascii
communitycreator
RELATED COURSES

View all Courses

Keep Exploring