zoukankan      html  css  js  c++  java
  • Guid的生成和数据修整(去除空格和小写字符)

    SqlServer实现

    SELECT  LOWER(LTRIM(RTRIM(REPLACE(NEWID(),'-',''))))
    NEWID()函数产生随机数,例如:F874153F-D99B-40A9-826B-D51948A33E22

    REPLACE(NEWID(),'-','')
    去除横线

    LOWER()
    字母小写

    C#代码实现

    string guid = System.Guid.NewGuid().ToString("N").ToLower();

            //
            // 摘要:
            //     根据所提供的格式说明符,返回此 System.Guid 实例值的字符串表示形式。
            //
            // 参数:
            //   format:
            //     一个单格式说明符,它指示如何格式化此 System.Guid 的值。format 参数可以是“N”、“D”、“B”、“P”或“X”。如果 format 为
            //     null 或空字符串 (""),则使用“D”。
            //
            // 返回结果:
            //     此 System.Guid 的值的字符串表示形式。
            //
            // 异常:
            //   T:System.FormatException:
            //     format 的值不为 null、空字符串 ("")、"N"、"D"、"B"、"P" 或 "X"。
            public string ToString(string format);

    Guid的带参数的ToString()方法的注释如上所示

    结果示例

    1、Guid.NewGuid().ToString("N") :        bf8b9c642ea5426f82499bb60681671b

    2、Guid.NewGuid().ToString("D") :       17e316f4-3f5b-46a0-ad68-58abb816a969

    3、Guid.NewGuid().ToString("B") :        {903c1236-fe24-43c2-b9b5-bec35d9a43a8}

    4、Guid.NewGuid().ToString("P") :       (bc13ad52-1c78-466f-893d-3a65c0b1a4d4)

    5、Guid.NewGuid().ToString("X"):        {0x3b9638cd,0xc271,0x4dbe,{0xa6,0xac,0x78,0xa5,0x8b,0x5d,0x1f,0x87}}

    注:format参数不区分大小写

  • 相关阅读:
    CF763C Timofey and Remoduling
    CF762E Radio Stations
    CF762D Maximum Path
    CF763B Timofey and Rectangles
    URAL1696 Salary for Robots
    uva10884 Persephone
    LA4273 Post Offices
    SCU3037 Painting the Balls
    poj3375 Network Connection
    Golang zip压缩文件读写操作
  • 原文地址:https://www.cnblogs.com/AlienXu/p/6875975.html
Copyright © 2011-2022 走看看