How to move the digits of a string with digits and letters to the beginning of the string in Rust

1 Answer

0 votes
fn move_digits_to_start(input: &str) -> String {
    let (digits, letters): (String, String) = input.chars().partition(|c| c.is_digit(10));
    format!("{}{}", digits, letters)
}

fn main() {
    let input = "d2a54be3c1";
    let result = move_digits_to_start(input);
    
    println!("{}", result); 
}


   
    
/*
run:
    
25431dabec
    
*/

 



answered May 27, 2025 by avibootz
...