C# 将GUID转换为最长16位的短字符串序号
C# 将GUID转换为最长16位的短字符串序号
扫一扫加微信
C# Code:
/// <summary>
/// 将GUID转换为最长16位的序号字符串
/// </summary>
/// <param name="removeZero">移除后面的000,d6acd6cb8621a000==>d6acd6cb8621a</param>
/// <returns></returns>
public static string GetSysID(bool removeZero = true)
{
long result = 1;
int index = 1;
byte[] bs = Guid.NewGuid().ToByteArray();
foreach (byte b in bs)
{
result *= ((int)b + index * 2);
index++;
}
var hex = string.Format("{0:x}", result);
//d6acd6cb8621a000==>d6acd6cb8621a
if (removeZero)//移除后面的000
{
while (hex.Substring(hex.Length - 1, 1) == "0")
hex = hex.Substring(0, hex.Length - 1);
}
return hex;
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// <summary>
/// 将GUID转换为最长16位的序号字符串
/// </summary>
/// <param name="removeZero">移除后面的000,d6acd6cb8621a000==>d6acd6cb8621a</param>
/// <returns></returns>
public static string GetSysID(bool removeZero = true)
{
long result = 1;
int index = 1;
byte[] bs = Guid.NewGuid().ToByteArray();
foreach (byte b in bs)
{
result *= ((int)b + index * 2);
index++;
}
var hex = string.Format("{0:x}", result);
//d6acd6cb8621a000==>d6acd6cb8621a
if (removeZero)//移除后面的000
{
while (hex.Substring(hex.Length - 1, 1) == "0")
hex = hex.Substring(0, hex.Length - 1);
}
return hex;
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
扫一扫加微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网