Skip to content

Instantly share code, notes, and snippets.

@JeremyLikness
Created September 2, 2017 14:26
Show Gist options
  • Select an option

  • Save JeremyLikness/ed4983e4f2dd939b8f7dad30dba78859 to your computer and use it in GitHub Desktop.

Select an option

Save JeremyLikness/ed4983e4f2dd939b8f7dad30dba78859 to your computer and use it in GitHub Desktop.
Function code for generating the short URL from an integer key
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