Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to check whether a character is a whitespace or not in Rust

2 Answers

0 votes
fn main() {
    let ch:char = ' ';

    if  (ch == ' ' ) || 
        (ch == '\t') || 
        (ch == '\n') || 
        (ch == '\r')
    {
       println!("yes");
    }
    else {
       println!("no");
    } 
}



 
/*
run:
 
yes
 
*/

 



answered May 5, 2023 by avibootz
0 votes
fn main() {
    let char1 = 'W';
    let char2 = ' ';  
    let char3 = '\n';      
    let char4 = 'r';
    let char5 = '\r';
    let char6 = '\t'; 

    println!("{}", char1.is_whitespace()); 
    println!("{}", char2.is_whitespace()); 
    println!("{}", char3.is_whitespace()); 
    println!("{}", char4.is_whitespace());  
    println!("{}", char5.is_whitespace());  
    println!("{}", char6.is_whitespace());  
}



 
/*
run:
 
false
true
true
false
true
true
 
*/

 



answered May 5, 2023 by avibootz

Related questions

2 answers 165 views
2 answers 201 views
1 answer 105 views
1 answer 137 views
1 answer 166 views
...