Re: Convert String To Guid
- From: "sloan" <sloan@xxxxxxxxx>
- Date: Mon, 15 May 2006 10:16:50 -0400
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" <MartinMoser@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D5632D53-59D9-4434-8000-B3C97722288D@xxxxxxxxxxxxxxxx
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
.
- Follow-Ups:
- Re: Convert String To Guid
- From: Martin Moser
- Re: Convert String To Guid
- Prev by Date: Re: Security.Permissions.SecurityPermission
- Next by Date: Re: ConfigurationSection question
- Previous by thread: Getting vertical scroll bar to work correctly after making datagrid multline
- Next by thread: Re: Convert String To Guid
- Index(es):
Relevant Pages
|