I'm working on making a URL shortener for my site, and my current plan (I'm open to suggestions) is to use a node ID to generate the shortened URL. So, in theory, node 26 might be short.com/z
, node 1 might be short.com/a
, node 52 might be short.com/Z
, and node 104 might be short.com/ZZ
. When a user goes to that URL, I need to reverse the process (obviously).
I can think of some kludgy ways to go about this, but I'm guessing there are better ones. Any suggestions?
ASCII to int:
ord('a')
gives 97
And back to a string:
str(unichr(97))
chr(97)
gives 'a'