newbie questions on C#

  • Thread starter Thread starter Danny Ni
  • Start date Start date
D

Danny Ni

Hi,
Does c# has functions to check if a String can be successfully converted to
a DateTime? VB.Net has IsDate()

And does c# has functions to convert a delimited string into an array?
VB.Net has Split.

Thanks in Advance
 
I generally do something like the following to find out if something is a
date. It's not necessarily the most performant (going into and out of
try...catch.. statements). If you are parsing a lot of dates, you may want
to look at the regular expressions class, but since there are so many
possible date formats, that can be tricky as well. (Unless you know in
advance the format that it should be)

bool isDate(string str)
{
bool isDate = true;
try
{
DateTime dt = DateTime.Parse(str);
}
catch (FormatException e)
{
isDate = false;
}
return isDate;
}

Additionally, you can add a project reference to Microsoft.VisualBasic.dll
and use:
Microsoft.VisualBasic.Information.IsDate (I think that's the right name,
Information may not be required)
 
Back
Top