How to efficiently extract tailing number from string

I am trying to extract tailing number from string.
My current implement seems not good, as there are dual collect::<String>.

fn main() {
    let x = "11 DDD12";
    let y = x
    let y: i32 = y.chars().rev().collect::<String>().parse().unwrap();
    println!("{:?}", y);

Use rsplit_once() to split off the end of the string based on some criterion:

let string = "11 DDD12";
let digits = string
    .rsplit_once(|c: char| !c.is_ascii_digit())
    .map_or(string, |(_head, digits)| digits);
let number: i32 = digits.parse().unwrap();



This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.