I have a string based code that can be either two or three characters in length and I am looking for some help in creating a function that will increment it.
Each \'
Based on @Martin answer, I found some error when two ZZ comes, this makes exception in code
private static String Increment(String s,bool IsFromRecursion=false)
{
String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//Added this condition
if (IsFromRecursion && string.IsNullOrEmpty(number))
{
return "1";
}
//Added this condition
char lastChar = s[s.Length - 1];
string fragment = s.Substring(0, s.Length - 1);
if (chars.IndexOf(lastChar) < 35)
{
lastChar = chars[chars.IndexOf(lastChar) + 1];
return fragment + lastChar;
}
return Increment(fragment,true) + '0';
}
When we call this method we pass first parameter only.