I would like to generate a GUID from the input string. Let's say I have guid received from the user which is
81a130d2-502f-4cf1-a376-63edeb000e9f
so I can do:
Guid g = Guid.Parse("81a130d2-502f-4cf1-a376-63edeb000e9f");
which is going to parse successfully.
But how to make user's life easier and allow to input:
81a130d2502f4cf1a37663edeb000e9f
which is without dashes, and still convert it to guid.
If I will try to use the same method it's gonna throw the exception complaining on the missing dashed in the guid format.
Any ideas?
The Parse method trims any leading or trailing white space from input and converts the string representation of a GUID to a Guid value. This method can convert strings in any of the five formats produced by the ToString(String) and ToString(String, IFormatProvider) methods, as shown in the following table.
A GUID is a 128-bit integer (16 bytes) value. That means that there are more than 300, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000 different values. A big number, isn't it? It is virtually impossible to have duplicates, so it is safe to use.
A GUID is a 16-byte (128-bit) number, typically represented by a 32-character hexadecimal string.
A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required.
Try
Guid.ParseExact("81a130d2502f4cf1a37663edeb000e9f", "N");
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