views:

89

answers:

2

I have a function that parses a string containing a date(and/or time) e.g. "2009-12-10". I get the order of year-month-day from the Short Date pattern. When going through the string I use Char.IsSeparator(ch) to figure out when the numbers end.

Now however in the case of Korean it seems the Char.IsSeparator(ch) returns false on separator characters. Is there any way to know whether the chars in between the numbers are separator regardless of region setting?

(I also parse strings that are more free containing things like "20 May 2009" so doing Char.IsAlphaNum() on the separator will not work either as I don't know the content basically)

Example inputs: "20.10.2009" "2009-05-20" "20 May 2009" "20.05.2009 10:00 AM" "1/1/2009" (in Singapore its D/M/Y in US it is M/D/Y") "Tisdag, 1 Januari 1962" (all strings localized)

Output would be an equivalent of a DateTime instance filled as much as possible (although we use our own types).

Korean seems to have a couple of characters in front of the time and as separator it looks like the symbols are different depending on position in the string.

+2  A: 

If you pick up the format using the current short format, you could perhaps also be able to pick up the separator through DateTimeFormatInfo.CurrentInfo.DateSeparator.

Fredrik Mörk
When I look in the debugger it seems its '-' however looking at the full date has the Korean chars.
Anders K.
A: 

Is there any reason why you need to parse the string manually?

If you used the built-in date/time parsing methods - Parse, ParseExact, TryParse or TryParseExact - then you could pass in the required culture-specific format info and let the framework worry about separators etc.

LukeH
I think with free hands and a full understanding of what this formatting module does I could have done it now, but when I did it was mainly to port an unmanaged C code C#. Especially since the formatting needs to be exactly like before (this routine is used by others and so on).
Anders K.
You are right. I just threw out the stuff and rewrote it using the standard .NET methods. Thanks for showing me the light :)
Anders K.