I have code which replaces the dash with empty strings in a GUID.
Replace(System.Guid.NewGuid.ToString, "-", "")
Would that remove the uniqueness of the guid?
Also can someone confirm this too?
We are storing GUIDs in our database as char(32). Is that okay? Because we have international users in different timezone, we're concerned that the character length could go over 32. Thanks.
That's just for convenience. GUID consists of 16 bytes which makes up 32 characters in hex text representation. Without hyphens GUIDs are harder to perceive by humans and harder to be recognized as GUIDs and not some random nature 16-byte numbers.
Guid should contain 32 digits with 4 dashes.
If you want to create an empty Guid, you can use Guid. Empty : it will return a Guid composed only by 0s, like 00000000-0000-0000-0000-000000000000.
A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated.
The dashes are always in the same place, so no, it will not reduce the uniqueness.
System.Guid.NewGuid().ToString("N");
Will generate a GUID without dashes, as in this documentation
Yes, it is OK to remove the dashes. The uniqueness of the Guid is guaranteed.
Dashes are only for readability: internally the Guid is made of 16 bytes.
You can see Microsoft and Wikipedia for more details.
Take a look at constructors too:
public Guid(int a, short b, short c, byte[] d); public Guid(int a, short b, short c, byte d, byte e, byte f, byte g, byte h, byte i, byte public Guid(uint a, ushort b, ushort c, byte d, byte e, byte f, byte g, byte h, byte i, byte j, byte k);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With