Search

date formatter create issues with string.Contains because of extra characters by Dominique Lorre

Closed
as By Design Help for as By Design

1
0
Sign in
to vote
Type: Bug
ID: 779284
Opened: 2/15/2013 3:20:09 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
string.Contains returns false when checking a formatted date because there are extra LRM (U+200E)characters inserted in the string:
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

Visual Studio 2012

Steps to reproduce

----------------------------------------------------------------------------------------------------

        private void showDateFormatterBug()
        {
            DateTimeFormatter myShortDateFormatter = new DateTimeFormatter("shortdate");
            DateTime myDate = new DateTime(2013,02,15) ;
            string formattedDate = myShortDateFormatter.Format(myDate);
            Debug.WriteLine("formattedDate:" + formattedDate);
            Debug.WriteLine("Contains 15/02?: " + formattedDate.Contains("15/02")) ;
            for (int i = 0; i < formattedDate.Length; i++)
            {
                Debug.WriteLine("formattedDate[" + i + "] = " + Convert.ToInt16(formattedDate[i]));
            }
        }

---------------------------------------------------------------------------------------------------

Product Language

French

Operating System

Windows 8

Operating System Language

French

Actual results

formattedDate:‎15‎/‎02‎/‎2013
Contains 15/02?: False
formattedDate[0] = 8206
formattedDate[1] = 49
formattedDate[2] = 53
formattedDate[3] = 8206
formattedDate[4] = 47
formattedDate[5] = 8206
formattedDate[6] = 48
formattedDate[7] = 50
formattedDate[8] = 8206
formattedDate[9] = 47
formattedDate[10] = 8206
formattedDate[11] = 50
formattedDate[12] = 48
formattedDate[13] = 49
formattedDate[14] = 51

Expected results

Contains should return true
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 4/4/2013 at 12:08 PM

Thanks for your suggestion. String.Contain is a generic purpose method that should work with all strings. so ignoring the mark can break other scenarios (which expect to account for the marks).
Posted by Dominique Lorre on 2/20/2013 at 10:37 AM
Thanks for your input, the reason why I need to do this is that my Windows Store application displays a list with dates and I wanted to be able to search by dates when using the Search charm.

Thank you also for the suggestion, I have done this exactly as a workaround, but I wanted to signal this issue because I was unaware that it was done by design.

Maybe string.Contains() could ignore these marks?
Posted by Microsoft on 2/20/2013 at 10:26 AM
DateTimeFormatter is designed to format dates to be consumed by the user. The RTL (0x200F) and LTR (0x200E) marks that are inserted are there to ensure that the date is formatted correctly. Without them the user will not always see the correct result. Parsing of these formatted dates is not a supported scenario. If you would like to provide more details as to why you are searching for the contents of a formatted date, we may be able to provide better guidance about how to accomplish your goal
Using a linguistic comparison would have succeeded (though I would bet that he is abusing this so wouldn't really want to suggest that)
The workaround can be stripping the LTM and RTM marks from the string before searching it.


Posted by Dominique Lorre on 2/18/2013 at 11:17 PM
Bug found while coding for Windows Store, not desktop.
Posted by Microsoft on 2/18/2013 at 10:51 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Sign in to post a workaround.