生成GUID没有连字符

编程入门 行业动态 更新时间:2024-10-11 21:30:45
本文介绍了生成GUID没有连字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用下面的语句在我的代码

I am generating a GUID using the following statement in my code

byte[ ] keyBytes = Encoding.UTF8.GetBytes( Guid.NewGuid( ).ToString( ).Substring( 0, 12 ) );

不过,会生成一个GUID的时候,我发现它包含了连字符了。我怎么去生成只包含字母(大写和小写)和数字的GUID?我不想连字符。有人可以给我这样的想法?

But, when a GUID is generated, I find that it contains the hyphen character too. How do I go about in generating a GUID with only letters (upper case and lower case) and numbers? I do not want the hyphen. Can someone give me so idea?

推荐答案

请注意,你是在谈论一个GUID的(规范)的字符串表示。该GUID本身实际上是一个128位的整数值。

Note that you are talking about the (canonical) string representation of a Guid. The Guid itself is actually a 128-bit integer value.

您可以使用带有的 Guid.ToString(字符串) 超载​​。

You can use the "N" specifier with the Guid.ToString(String) overload.

Guid.NewGuid().ToString("N");

默认情况下字母都是小写。

By default letters are lowercase. A Guid with only uppercase letters can only be achieved by manually converting them all to uppercase, example:

Guid.NewGuid().ToString("N").ToUpper();

一个没有意义的。一个GUID字符串表示是十六进制的,因此总会(以及最有可能的),同时包含。

A guid with only either letter or digits makes no sense. A guid string representation is hexadecimal, and thus will always (well most likely) contain both.

更多推荐

生成GUID没有连字符

本文发布于:2023-11-29 13:46:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646554.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   GUID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!