| Re: [aus-dotnet] IsDate function |
- From: Shane Norris
- Subject: Re: [aus-dotnet] IsDate function
- Date: Tue, 21 Sep 2004 17:39:23 +1000
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
That sounds like a black smudge against the exceptions way of error handling to me. In the olden days of error codes there would be no questions about passing something through a parser and if it succeeded then it was valid. It just seems a little broken to me that you should have to write your own mini parser to see if its gonna make it through the real deal. - Not that I don't prefer try/catch in my code instead of the old way of if/then/else/if/then/if/else/else/if/... anyhow just an observation... Shane On Tue, 21 Sep 2004 16:38:52 +1000, jmplun <jmplun@xxxxxxxxxxxxxx> wrote: > Actually it is very bad form to use an exception to determine whether > something is a date or not. > For one thing it is a lot slower than doing a comparison. > Another, exceptions are for just that, if you are doing a check to see > if something is a date or not, then it shouldn't be an exception. > > Look at regExp and use that to identify a valid date > E.g. > > http://www.google.com/search?hl=en&ie=UTF-8&q=regexp+.Net+date > > Jarrad > > > > -----Original Message----- > From: dotnet-owner@xxxxxxxxxxx [mailto:dotnet-owner@xxxxxxxxxxx] On > Behalf Of Sean Malloy > Sent: Tuesday, September 21, 2004 4:24 PM > To: 'dotnet@xxxxxxxxxxx' > Subject: RE: [aus-dotnet] IsDate function > > > This is very slow if the input param is null > > if the input param being null makes it slow, why don't you place a check > for that first, if null return false or something? > > C# version (yelch VB) > > bool IsDate(string input) > { > if (input == null || input.Length == 0) > return false; > > try > { > DateTime.Parse(input); > return true; > } > catch (FormatException) > { > return false; > } > } > _________________ > You are a part of the Australian "dotnet" mailing list. > To unsubscribe send "unsubscribe dotnet" or to re-subscribe send > "subscribe dotnet Your Name" in the body of the email to: > imailsrv@xxxxxxxxxxx List managed by: http://www.stanski.com > > > > > _________________ > You are a part of the Australian "dotnet" mailing list. > To unsubscribe send "unsubscribe dotnet" or to re-subscribe send "subscribe dotnet Your Name" in the body of the email to: imailsrv@xxxxxxxxxxx > List managed by: http://www.stanski.com > _________________ You are a part of the Australian "dotnet" mailing list. To unsubscribe send "unsubscribe dotnet" or to re-subscribe send "subscribe dotnet Your Name" in the body of the email to: imailsrv@xxxxxxxxxxx List managed by: http://www.stanski.com
(Click here for more information on the aus-dotnet mailling list)
- References:
- RE: [aus-dotnet] IsDate function, Sean Malloy
- RE: [aus-dotnet] IsDate function, jmplun
- Prev by Date: RE: [aus-dotnet] A Big Change: I'm Joining Microsoft
- Next by Date: RE: [aus-dotnet] Way off topic isp in belgium
- Previous by thread: RE: [aus-dotnet] IsDate function
- Next by thread: RE: [aus-dotnet] IsDate function
- Index(es):
