by Michael S. Kaplan, published on 2006/10/06 03:00 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/10/06/795575.aspx
The question went something like this:
Recently we had to make the date returned by GetDateFormat() to be LTR/RTL compliant and hence we are specifying DATE_LTRREADING/ DATE_RTLREADING in the flags for the same. It looks like with this flag, GetDateFormat() returns the date with some non-text characters embedded in it (like 0x200e for LTR and 0x200f for RTL). This fails the further processing of the returned date string. Can you please help us in the following:
- Is this by design?
- What should I do to get a normal text string from the string returned by GetDateFormat()? I don’t see character replacement a very neat option!
The answer to the first question is of course yes! As I have mentioned in the past, the whole point of these flags is to insert U+200e (a.k.a. LEFT-TO-RIGHT MARKER) or U+200f (a.k.a. RIGHT-TO-LEFT MARKER), depending on what flag you pass. It doesn't make sense to request that an NLS API function like GetDateFormat perform an action but then later to be unhappy about the action being petrformed.....
The second question kind of suggests an easy bit of code -- just loop through the string, copying it character by character, and with each occurrence of the one of formatting characters, you simply don't copy it over. Given how small the strings are, this should be fairly straightforward. :-)
Now over in the managed world, where there is locale sensitive formattig and parsing, the ability to insert these characters does not exist (presumably if it were ever added as an option for date formatting, date parsing would be modified to know about the characters, too). But for noew in the managed world you are kind of on your own with this type of situation....
Though on the whole, to help with the original question, I think it is important to understand what a flag does before simply adding it. Just as in life, doing "the right thing" without understanding the context of why it is "the right thing to do" is simply not going to get a person very far....
This post brought to you by U+200e and U+200f (a.k.a. LEFT-TO-RIGHT MARKER and RIGHT-TO-LEFT MARKER)
# benkaras on 11 Oct 2006 1:59 AM:
I just had to write such a stripping function to prepare a formatted string for a Unicode->OEM conversion. Check my post to see just how easy it is: