GUID 的格式始终相同吗?

发布于 2024-12-10 04:28:21 字数 179 浏览 0 评论 0原文

GUID 你得到类似 aaaef973-d8ce-4c92-95b4-3635bb2d42d5

它总是一样吗?它是否总是具有以下格式

8 char“-”,4 char“-”,4 char“-”,4 char“-”,12 char

我问因为我需要转换不带“-”的GUID以GUID带“-”的副签证。

GUID you get something like aaaef973-d8ce-4c92-95b4-3635bb2d42d5

Is it always the same? Is it always going to have the following format

8 char "-", 4 char "-", 4 char "-", 4 char "-", 12 char

I'm asking because i need to convert a GUID without "-" to GUID with "-" and vice visa.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

儭儭莪哋寶赑 2024-12-17 04:28:21

不;还有其他格式,例如您列出的除大括号之外的格式。还有更复杂的格式。以下是 MSDN 列出的一些格式:

UUID 格式

  • 32 位数字:00000000000000000000000000000000 (N)
  • 由连字符分隔的 32 位数字:00000000-0000-0000-0000-000000000000 (D)
  • 由连字符分隔的 32 位数字,用大括号括起来:{00000000-0000-0000-0000-000000000000} (B)
  • 由连字符分隔的 32 位数字,括在括号内:(00000000-0000-0000-0000-000000000000) (P)
  • 用大括号括起来的四个十六进制值,其中第四个值是也用大括号括起来的八个十六进制值的子集:{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00}} (X)

MSDN

No; there are other formats, such as the format you listed except with braces. There's also more complex formats. Here are some of the formats MSDN lists:

UUID formats

  • 32 digits: 00000000000000000000000000000000 (N)
  • 32 digits separated by hyphens: 00000000-0000-0000-0000-000000000000 (D)
  • 32 digits separated by hyphens, enclosed in braces: {00000000-0000-0000-0000-000000000000} (B)
  • 32 digits separated by hyphens, enclosed in parentheses: (00000000-0000-0000-0000-000000000000) (P)
  • Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces: {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} (X)

MSDN

美煞众生 2024-12-17 04:28:21

您应该简单地将其视为 32 个十六进制字符,可以有多种表示方式。查看维基百科文章以获取更多信息,包括它们通常如何编写的描述。

对于您的转换,您应该真正依赖静态 Guid.Parse( )方法。混合使用您的示例和 icktoofay 的答案 中的示例,效果很好:

        var z = Guid.Parse("aaaef973-d8ce-4c92-95b4-3635bb2d42d5");
        z = Guid.Parse("{aaaef973-d8ce-4c92-95b4-3635bb2d42d5}");
        z = Guid.Parse("{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}");

然后用于使用或不使用连字符等输出它们您可以使用 Guid.ToString() 方法,具有已建立的格式代码之一。

You should simply rely upon it being 32 hexadecimal characters, there can be a variety of ways to present it. Check the Wikipedia article for more information, including a description of how they are commonly written.

For your conversion you should really rely on the static Guid.Parse() methods. Using a mix of your example and the ones in icktoofay's answer, this works nicely:

        var z = Guid.Parse("aaaef973-d8ce-4c92-95b4-3635bb2d42d5");
        z = Guid.Parse("{aaaef973-d8ce-4c92-95b4-3635bb2d42d5}");
        z = Guid.Parse("{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}");

then for outputting them with or without hyphens etc you can use the Guid.ToString() method with one of the established format codes.

情痴 2024-12-17 04:28:21

大多数情况下,GUIDS 是 32 个字符的十六进制字符串,例如 {21EC2020-3AEA-1069-A2DD-08002B30309D}(除非它们以 Base-64 编码),并且通常存储为128 位整数。但它们并不总是有连字符。

Most of the time, GUIDS are 32-character hexadecimal strings such as {21EC2020-3AEA-1069-A2DD-08002B30309D} (unless they're encoded in Base-64), and are usually stored as a 128-bit integers. They won't always have hyphens, though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文