ADVERTISEMENT
ADVERTISEMENT

Rust program to check whether a given character is a whitespace character or not

Given a character, we have to check whether a given character is whitespace or not using Rust program.
Submitted by Nidhi, on September 28, 2021

Problem Solution:

Here, we will create two-character variables and check created variable contains a whitespace character or not.

Program/Source Code:

The source code to check a given character is a whitespace character or not is given below. The given program is compiled and executed successfully.

// Rust program to check whether a given character 
// is a whitespace character or not

fn main() {
    let mut ch:char = ' ';
    let mut ch1:char = 'B';
    
    if ( (ch == ' ' ) || 
         (ch == '\t') || 
         (ch == '\n') || 
         (ch == '\r')  
        )
    {
       println!("Variable ch contains whitespace character");
    }
    else
    {
       println!("Variable ch does not contain whitespace character");
    }
    
    if ( (ch1 == ' ' ) || 
         (ch1 == '\t') || 
         (ch1 == '\n') || 
         (ch1 == '\r') 
        )
    {
       println!("Variable ch1 contains whitespace character");
    }
    else
    {
       println!("Variable ch1 does not contain whitespace character");
    }
}

Output:

Variable ch contains whitespace character
Variable ch1 does not contain whitespace character

Explanation:

Here, we created two character variables ch and ch1 that are initialized with ' ' and 'B' respectively. Then we checked the given characters contains whitespace characters or not and printed the appropriate message.

Rust Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.