There are 26 characters in the alphabet (abc..yz) and 10 digits (0..9). That gives us a lexicon of 62 characters to use if we go case sensitive.
At the moment we are building a part of a filename based on an ID in our database. These numbers can get quite long so we would like to shorten them. For example instead of having:
file_459123.exe
We would rather:
file_aB5.exe
Does anyone have a method in C# that can convert an int into a shorter case sensitive string, and convert a case sensitive string back into an int?
Example (doesn't have to be this pattern):
1 = 1
2 = 2
...
9 = 9
10 = a
11 = b
...
36 = z
37 = A
just expanding M4Ns solution to a generic class....
and then you can do...
Despite the Base64 references, here's a generic (non-optimized) solution:
Depending on your situation you might want to look at using Base32 as the restricted character set may be easier to read (I.E., some users cannot easily distinguish the difference between zero and the letter o).
You can find examples here and here.
Try Base64