How to determine if a string contains a GUID vs just a string of numbers.
will a GUID always contain at least 1 alpha character?
When I'm just testing a string to see if it is a GUID, I don't really want to create a Guid object that I don't need. So...
public static class GuidEx
{
public static bool IsGuid(string value)
{
Guid x;
return Guid.TryParse(value, out x);
}
}
And here's how you use it:
string testMe = "not a guid";
if (GuidEx.IsGuid(testMe))
{
...
}
Will return the Guid if it is valid Guid, else it will return Guid.Empty
if (!Guid.TryParse(yourGuidString, out yourGuid)){
yourGuid= Guid.Empty;
}
Use GUID constructor standard functionality
Public Function IsValid(pString As String) As Boolean
Try
Dim mGuid As New Guid(pString)
Catch ex As Exception
Return False
End Try
Return True
End Function