是否有可能产生的YouTube(N7Et6c9nL9w)短GUID是怎样的?
Is it possible to generate short GUID like in YouTube (N7Et6c9nL9w)?
如何能不能做到?我想用它的Web应用程序。
How can it be done? I want to use it in web app.
您可以使用的Base64:
You could use Base64:
string base64Guid = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
这会产生像字符串E1HKfn68Pkms5zsZsvKONw ==
。由于GUID永远是128位,则可以省略 ==
,你知道永远是present在年底会给你一个22字符的字符串。这不是短的YouTube虽然。
That generates a string like E1HKfn68Pkms5zsZsvKONw==
. Since a GUID is always 128 bits, you can omit the ==
that you know will always be present at the end and that will give you a 22 character string. This isn't as short as YouTube though.