fn separate_numbers_and_non_numbers(input: &str) -> Vec { let mark = "!"; let s = format!("{}{}", mark, input); let mut result = vec![]; let mut temp_str = String::new(); let mut prev_char_digit = s.chars().next().map_or(false, |c| c.is_digit(10)); for c in s.chars().skip(1) { let is_digit = c.is_digit(10); if prev_char_digit == is_digit { temp_str.push(c); } else { result.push(temp_str.clone()); temp_str.clear(); temp_str.push(c); prev_char_digit = is_digit; } } result.push(temp_str); result } fn main() { let s = "abc123def456xyz"; let result = separate_numbers_and_non_numbers(s); println!("Result: {:?}", result); // ["abc", "123", "def", "456", "xyz"] }