Can anyone help with the logic for the below scenario please?
**Input -> Output**
00000 --> 00001
00009 --> 0000A
0000Z --> 00010
..
..
0002Z --> 00030
00039 --> 0003A
Any suggestions please?
EDIT Thanks all for your suggestions. :) This is what I tried and it works, not sure if could break at some condition though? :/
public static void Main(string[] args)
{
string number = "0001Z";
var result = Increment(number);
}
private static String Increment(String number)
{
String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char lastChar = number[number.Length - 1];
string fragment = number.Substring(0, number.Length - 1);
if (chars.IndexOf(lastChar) < 35)
{
lastChar = chars[chars.IndexOf(lastChar) + 1];
string nextNumber = fragment + lastChar;
return nextNumber;
}
return Increment(fragment) + '0';
}
PS: Increment an index that uses numbers and characters (aka Base36 numbers) - this is where I got it from, so may be duplicate question.. sorry.