Monday, April 30, 2012

String Parsing a Time

I need to obtain a time in the format of "07:30 am" (not case-sensitive). I'm reading a file which has this in the format "07:30am". Eventually I will be constructing a DateTime from this, so I just need to get this back with a space before the am/pm part.



I can detect the occurrence of the a or p using this:



if(startString.IndexOfAny("ap".ToCharArray()) != -1)
{

}


What's the best ways to do this? I'm guessing I will end up with two strings that can be concatenated with a space? Can Split be used with the above snippet to achieve this?





No comments:

Post a Comment