How about this?
static string TryToIncrement(string tag)
{
string result = null;
Match m = Regex.Match(tag, @"^(.*?)(\d+)$");
if (m.Success) {
string head = m.Groups[1].Value;
string tail = m.Groups[2].Value;
string format = new string('0', tail.Length);
int incremented = int.Parse(tail) + 1;
result = head + incremented.ToString(format);
}
return result;
}
Cheers
Andi