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.
I have a couple of methods that I made to convert an integer to/from a different base. I'm sure they probably could be improved. But they may get you started. So convert your base 36 "number" to int, increment by 1, then convert back to base 36. This method uses recursion which is probably not necessary. I'd be interested to know if there are any more efficient methods for this.
These method assumes no other characters besides 0-9 and A-Z
Output: