How to remove the first word from string in Rust

1 Answer

0 votes
fn trim_first_word(input: &str) -> &str {
    if let Some(pos) = input.find(|c| c == ' ' || c == '\t') {
        &input[pos + 1..]
    } else {
        input
    }
}

fn main() {
    let s = "c++ c c# java php rust";
    
    let trimmed = trim_first_word(s);
    
    println!("{}", trimmed);
}



/*
run:

c c# java php rust

*/

 



answered Sep 25, 2025 by avibootz
...