How to trim punctuation in Rust

1 Answer

0 votes
fn main() {
    let array = [
        "Rust!!!",
        "...c",
        "java,,,",
        "c++",
        "**python__",
        ".S.Q.L.",
    ];

    for s in &array {
        println!("{}", trim_punctuation(s));
    }
}

fn trim_punctuation(s: &str) -> String {
    let chars_to_trim: &[_] = &['*', '!', ',', '.', '_'];
    
    s.trim_matches(chars_to_trim).to_string()
}


 
 
/*
run:

Rust
c
java
c++
python
S.Q.L

*/

 



answered Nov 23, 2024 by avibootz

Related questions

1 answer 236 views
2 answers 349 views
1 answer 243 views
1 answer 233 views
233 views asked Jul 6, 2024 by avibootz
1 answer 214 views
214 views asked Nov 23, 2024 by avibootz
1 answer 209 views
209 views asked Nov 23, 2024 by avibootz
1 answer 207 views
207 views asked Nov 23, 2024 by avibootz
...