I am converting a string to a guid to check if the string is a valid guid , in c# .net 4.0
The string is :
string guid = "11111111-1111-1111-1111-111111111111";
This guid should be invalid for me , even though it have as many characters as a guid have. Is there a way to check if a guid looks like a “normal” guid with different chars and numbers?
All these methods dont work because they return the guid is valid for me.
Guid.Parse
Guid.TryParse
Guid.TryParseExact
Thank you!
EDIT :
To clarify, i need to check if my guid is like these Guids : dc6a1ad8-4743-4487-a28e-54d31870dfcb
We can discard the word “invalid” and “valid” because people seem to focus a bit on that. So i need make sure a guid looks more like this : dc6a1ad8-4743-4487-a28e-54d31870dfcb instead of this : 11111111-1111-1111-1111-111111111111
If you just want to check whether the
Guidhas different characters, you can check the number of distinct bytes it contains:For
Guid.Emptyor11111111-1111-1111-1111-111111111111, the result will be1.For
dc6a1ad8-4743-4487-a28e-54d31870dfcb, the result is16.You’ll just need to decide how large the number needs to be for you to accept the
Guidas “normal”.