I have a string which i need to increment by 1 The string has both characters and numeric values.
The string layout i have is as follows \"MD00494\"
How woul
Here's my solution:
string str = Console.ReadLine();
string digits = new string(str.Where(char.IsDigit).ToArray());
string letters = new string(str.Where(char.IsLetter).ToArray());
string newStr;
int number;
if (!int.TryParse(digits, out number))
{
Console.WriteLine("Something weird happened");
}
if (digits.StartsWith("0"))
{
newStr = letters + (++number).ToString("D5");
}
else
{
newStr = letters + (++number).ToString();
}
Try it!