Skip to content

Instantly share code, notes, and snippets.

@lski
Last active April 16, 2019 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lski/0e4209d49c16053a673d529037f81714 to your computer and use it in GitHub Desktop.
Save lski/0e4209d49c16053a673d529037f81714 to your computer and use it in GitHub Desktop.
A short format GUID/UUID based on Mads Kristensens work
public static class GuidExtensions {
/// <summary>
/// Converts a Guid into a short format useful urls
/// </summary>
/// <remarks>
/// See <see>https://madskristensen.net/blog/A-shorter-and-URL-friendly-GUID</see> for a more detailed explantion.
/// </remarks>
public static string ToShortFormat(this Guid guid) =>
Convert.ToBase64String(guid.ToByteArray())
.Replace("/", "_")
.Replace("+", "-")
.Substring(0, 22);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment