How to extract only words with first-letter lowercase from a string in Rust

1 Answer

0 votes
fn lowercase_words(s: &str) -> Vec<&str> {
    s.split_whitespace()
        .filter(|w| w.chars().next().map(|c| c.is_lowercase()).unwrap_or(false))
        .collect()
}

fn main() {
    let s = "Rust php Go java CPP python nodejs";

    let result = lowercase_words(s);

    for w in result {
        println!("{}", w);
    }
}



/*
run:

php
java
python
nodejs

*/

 



answered Jan 16 by avibootz

Related questions

...