有什么办法来创建像GUID短很短的唯一的代码? [英] Is there any way to create a short unique code like short GUID?
本文介绍了有什么办法来创建像GUID短很短的唯一的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要创建一个简短的GUID。有什么办法来创建像GUID短很短的唯一的代码?
我想创建一票跟踪号码。
I want to create a short GUID. Is there any way to create a short unique code like short GUID? I want to create a ticket tracking number.
推荐答案
GUID的长度为128位(16字节),因此,如果要创建一个简短的GUID,你必须改变GUID的编码。
The length of GUID is 128bits(16bytes), so if you want to create a short GUID , you have to change GUID's encoding.
例如,你可以通过用户的base64或ASCII85。
For instance, you can user base64 or ASCII85.
/// <summary>
/// Creates a GUID which is guaranteed not to equal the empty GUID
/// </summary>
/// <returns>A string</returns>
public static string CreateGuid()
{
Guid guid = Guid.Empty;
while (Guid.Empty == guid)
{
guid = Guid.NewGuid();
}
// Uses base64 encoding the guid.(Or ASCII85 encoded)
// But not recommend using Hex, as it is less efficient.
return Convert.ToBase64String(guid.ToByteArray());
}
这篇关于有什么办法来创建像GUID短很短的唯一的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文