Rust Program to Check Whether a Given Character Is a Punctuation Mark or Not

You are currently viewing Rust Program to Check Whether a Given Character Is a Punctuation Mark or Not

Rust program to check whether a given character is a punctuation mark or not

// Rust program to check a given character 
// is a punctuation mark or not

fn main() {
    let ch:char = '#';
    
    if ( ch == '!' || ch == '\"' || ch == '#' || ch == '

character '#' is a punctuation mark
|| ch == '%' || ch == '&' || ch == '\'' || ch == '(' || ch == ')' || ch == '*' || ch == '+' || ch == ',' || ch == '-' || ch == '.' || ch == '/' || ch == ':' || ch == ';' || ch == '<' || ch == '=' || ch == '>' || ch == '?' || ch == '@' || ch == '[' || ch == '\\' || ch == ']' || ch == '^' || ch == '`' || ch == '{' || ch == '|' || ch == '}') { println!("character '{}' is a punctuation mark",ch); } else { // Rust program to check a given character // is a punctuation mark or not fn main() { let ch:char = '#'; if ( ch == '!' || ch == '\"' || ch == '#' || ch == '$' || ch == '%' || ch == '&' || ch == '\'' || ch == '(' || ch == ')' || ch == '*' || ch == '+' || ch == ',' || ch == '-' || ch == '.' || ch == '/' || ch == ':' || ch == ';' || ch == '<' || ch == '=' || ch == '>' || ch == '?' || ch == '@' || ch == '[' || ch == '\\' || ch == ']' || ch == '^' || ch == '`' || ch == '{' || ch == '|' || ch == '}') { println!("character '{}' is a punctuation mark",ch); } else { println!("character '{}' is a punctuation mark", ch); } }

Output

character '#' is a punctuation mark

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply