If the text component of the line is unknown (with or without a number at the end of the line), options for this function may be useful:
private string increment_number_at_end_of_string(string text_with_number_at_the_end) { string text_without_number = text_with_number_at_the_end.TrimEnd('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); string just_the_number = text_with_number_at_the_end.Substring(text_without_number.Length); int number = -1; if (int.TryParse(just_the_number, out number)) { return text_without_number + (number + 1).ToString(); } return text_with_number_at_the_end; }
bertie
source share