Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

rust
ascii
graph
communitycreator

What is the character.is_ascii_graphic() method in Rust?

okwudili onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

We use the is_ascii_graphic() method to check if a character is an ASCII graphic character. A graphic character is a character that is to be written, printed, shown, etc., in a way that humans can understand. ASCII is a popular encoding for information and communication among computers.

Syntax

character.is_ascii_graphic()
Syntax for is_ascii_graphic() in Rust

Parameter

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

Return value

The value returned is a Boolean value. If the character is an ASCII graphic character, then a true will be returned. Otherwise, a false is returned.

Example

fn main(){
// create some characters
let char1 = 't';
let char2 = '❤'; // non ASCII
let char3 = '☀'; // non ASCII
let char4 = 'w';
let char5 = 'n';
// check if characters are ascii graphic characters
println!("{} is ASCII? {}", char1, char1.is_ascii_graphic()); // true
println!("{} is ASCII? {}", char2, char2.is_ascii_graphic()); // false
println!("{} is ASCII? {}", char3, char3.is_ascii_graphic()); // false
println!("{} is ASCII? {}", char4, char4.is_ascii_graphic()); // true
println!("{} is ASCII? {}", char5, char5.is_ascii_graphic()); // true
}
Check if a character is an ASCII graphic character

Explanation

  • Lines 3–7: We create some characters (char1 , char2 , char3 , char4 , char5).
  • Lines 10–14: We check if each of the characters we created is an ASCII graphic character.

RELATED TAGS

rust
ascii
graph
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring