YouTube-like GUID

后端 未结 8 1843
灰色年华
灰色年华 2020-12-07 16:17

Is it possible to generate short GUID like in YouTube (N7Et6c9nL9w)?

How can it be done? I want to use it in web app.

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 16:59

    You could use Base64:

    string base64Guid = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
    

    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.

提交回复
热议问题