Last active
April 16, 2019 11:20
-
-
Save lski/0e4209d49c16053a673d529037f81714 to your computer and use it in GitHub Desktop.
A short format GUID/UUID based on Mads Kristensens work
This file contains 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 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