GUID 的格式始终相同吗?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不;还有其他格式,例如您列出的除大括号之外的格式。还有更复杂的格式。以下是 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:
您应该简单地将其视为 32 个十六进制字符,可以有多种表示方式。查看维基百科文章以获取更多信息,包括它们通常如何编写的描述。
对于您的转换,您应该真正依赖静态 Guid.Parse( )方法。混合使用您的示例和 icktoofay 的答案 中的示例,效果很好:
然后用于使用或不使用连字符等输出它们您可以使用 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:
then for outputting them with or without hyphens etc you can use the Guid.ToString() method with one of the established format codes.
大多数情况下,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.