How to remove the leading and trailing commas from a string in Rust

1 Answer

0 votes
fn main() {
    let s = ",,,Rust,,";
    
    let s = s.trim_matches(',');
    
    println!("'{}'", s);
}



/*
run:

'Rust'
     
*/
 

 



answered Mar 6, 2025 by avibootz

Related questions

3 answers 147 views
2 answers 123 views
3 answers 137 views
2 answers 108 views
1 answer 112 views
...