pub fn increment_number_in_string(s: &str) -> String
Expand description

Copy a string while incrementing its contained number

  • If the string contains one or more numbers, the last one gets incremented
  • If it does not contain a number, a “1” is appended instead

This way, the returned number is guaranteed to be different from the input string. That’s useful for example to generate unique, incrementing pin numbers like “X1”, “X2”, “X3” etc.

Arguments

  • s - The input string.

Returns

Returns a new string with the incremented number.