Created
September 2, 2017 14:26
-
-
Save JeremyLikness/ed4983e4f2dd939b8f7dad30dba78859 to your computer and use it in GitHub Desktop.
Function code for generating the short URL from an integer key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static readonly string Alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"; | |
| public static readonly int Base = Alphabet.Length; | |
| public static string Encode(int i) | |
| { | |
| if (i == 0) | |
| { | |
| return Alphabet[0].ToString(); | |
| } | |
| var s = string.Empty; | |
| while (i > 0) | |
| { | |
| s += Alphabet[i % Base]; | |
| i = i / Base; | |
| } | |
| return string.Join(string.Empty, s.Reverse()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment