How to calculate string length without spaces in Rust

1 Answer

0 votes
fn main() {
    let s = "Rust Programming Language";
    
    let length_without_spaces = s.chars().filter(|&ch| !ch.is_whitespace()).count();
    
    println!("Length without spaces: {}", length_without_spaces);
}

 
  
/*
run:
  
Length without spaces: 23
 
*/

 



answered Jan 11, 2025 by avibootz

Related questions

...