What is character.is_ascii_alphanumeric() in Rust?

Overview

Alphanumeric characters are the combined set of 26 alphabetic characters A to Z, and the 10 Arabic numerals, 0 to 9. ASCII is an encoding system for information interchange. As we share information between computers, data is encoded, especially in ASCII. With the is_ascii_alphanumeric() method, we can check if a character is an ASCII alphanumeric character.

Syntax

character.is_ascii_alphanumeric()
Syntax for is_ascii_alphanumeric() method in Rust

Parameters

character: This is the character we want to find out if it is an ASCII alphanumeric character or not.

Return value

This method returns a Boolean value. If the character is an ASCII alphanumeric character, then a true is returned; otherwise, a false is returned.

Example

fn main(){
// initialise some characters
let char1 = 'E';
let char2 = '+';
let char3 = '=';
let char4 = '3';
let char5 = '!';
// check if characters are alphanumeric
println!("{}", char1.is_ascii_alphanumeric());
println!("{}", char2.is_ascii_alphanumeric());
println!("{}", char3.is_ascii_alphanumeric());
println!("{}", char4.is_ascii_alphanumeric());
println!("{}", char5.is_ascii_alphanumeric());
}

Explanation

  • Lines 3–7: We initialize some characters. Some of them are alphanumeric and others are not.
  • Line 10–14: We check if the characters are ASCII alphanumeric using the is_ascii_alphanumeric() method. Then we print the result to the console.

Free Resources