Exception handling is expensive.... and this if this is not "exceptional",
as in....only happens in a blue moon, Id avoid the try/catch
From
http://geekswithblogs.net/jawad/archive/2005/05/20/GuidVerifier.aspx
private static Regex isGuid = new
Regex(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F
]{4}\-[0-9a-fA-F]{12}(\}){0,1}$", RegexOptions.Compiled);
internal static bool IsGuid(string
candidate, out Guid output)
{
bool isValid = false;
output=Guid.Empty;
if(candidate!=null)
{
if
(isGuid.IsMatch(candidate))
{
output=new Guid(candidate);
isValid = true;
}
}
return isValid;
}
rewrite that as your procedure. it avoids the try/catch, and gets the
purpose accomplished.
Martin Moser said:
Does somebody know if there's a faster way to convert a string to a guid, than:
Try
gID = New Guid(myString)
Catch ex As Exception
gID = Guid.Empty
End Try
even if it's not clear that the string contains a valid guid?
tia
Martin