C# 将GUID转换为最长16位的短字符串序号
作者:C/S框架网|www.cscode.ne  发布日期:2021-03-20 13:20:44
  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





C/S框架网|原创精神.创造价值.打造精品

扫一扫加微信
C/S框架网作者微信 C/S框架网|原创作品.质量保障.竭诚为您服务

上一篇 下一篇