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 144 views
2 answers 120 views
3 answers 133 views
2 answers 101 views
1 answer 101 views
...