Is the GUID format always the same?

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

Is it always the same? Will always have the following format

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

I ask because I need to convert a GUID without a β€œ-” to a GUID with a β€œ-” and a visa type.

+8
string c # guid
source share
3 answers

Not; There are other formats, such as the format you specified, except for the brackets. There are also more complex formats. Here are some of the MSDN list formats:

UUID Formats

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

- MSDN

+22
source share

You just have to rely on the fact that these are 32 hexadecimal characters, there can be many ways to represent it. See the Wikipedia article for details, including a description of how they are usually written.

For your conversion, you must really rely on the static methods of Guid.Parse () . Using a combination of your example and the ones listed in icktoofay answer , this works great:

  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 you can use the Guid.ToString () method with one of the installed format codes to display them with hyphens or without them.

+4
source share

In most cases, GUIDS are 32-character hexadecimal strings, such as {21EC2020-3AEA-1069-A2DD-08002B30309D} (if they are not encoded in Base-64) and are usually stored as 128-bit integers. However, they will not always have hyphens.

0
source share

All Articles