简体   繁体   中英

String retrieved as shell32 GetDetailsOf never '=='s hard coded string that appear the same. Unable to parse with DateTime.Parse

My real aim is to DateTime.Parse a date string from Shell32 GetDetailsOf Extended date field. While furthering my debuging, I simply created a string that appears the same and DateTime is able to parse it. When I view the 2 strings in Memory, they appear different.

The first few Bytes only.....

s > 4c 22 2e 63 16 00 00 00 0e 20 39 00 2f 00 0e 20 35 00 2f

q > 4c 22 2e 63 11 00 00 00 39 00 2f 00 35 00 2f 00 32 00 30

Is there a way to format the string so that I am able to parse it with DateTime.Parse?

        Shell32.Shell shell = new Shell32.Shell();
        Shell32.Folder objFolder;
        objFolder = shell.NameSpace(folder);
        int i = 0;
        foreach (Shell32.FolderItem2 item in objFolder.Items())
        {
            if (item.Type == "Windows Recorded TV Show")
            {
                mediaArray[i, 0] = objFolder.GetDetailsOf(item, 21);   // serName
                mediaArray[i, 1] = objFolder.GetDetailsOf(item, 254);  // epName
                mediaArray[i, 2] = objFolder.GetDetailsOf(item, 259);  // desc
                mediaArray[i, 3] = objFolder.GetDetailsOf(item, 258);  // broad Date


                DateTime dateValue;
                CultureInfo culture;
                DateTimeStyles styles;
                styles = DateTimeStyles.AssumeLocal;
                culture = CultureInfo.CreateSpecificCulture("en-US");
                string s = mediaArray[i, 3].Normalize();  //  Guessing this string isn't ASCII?                                         
                string q = "9/5/2014 12:00 AM";           
                if (s == q) { MessageBox.Show("They are the same."); } // Never Entered. ):
                MessageBox.Show(s+"\n"+q); //  They appear exactly the same!

                dateValue = DateTime.Parse(q, culture, styles); // parses correctly
                dateValue = DateTime.Parse(s, culture, styles); // fails at runtime


                i++;
            }
        }

How can I extract the date from the "Media Created" column of a video file?

Eh, I found the answer here..

I had been searching since yesterday evening and when I finally post the question, I find the answer within 30 min.

Apparently the characters (char)8206 (char)8207 exist in the string s of GetDetailsOf. These characters appear invisible when I MessageBox.Show() them but never the less removing them resolved my issue.

 // These are the characters that are not allowing me to parse into a DateTime
 char[] charactersToRemove = new char[] 
 {
  (char)8206,
  (char)8207
 };

  // Removing the suspect characters
  foreach (char c in charactersToRemove)
  value = value.Replace((c).ToString(), "").Trim();

I am aware of the difference between == and String.Equals. But I was specifically using == to debug the problem.

I found the chars 8206 and 8207 by trying to remove them with the help of another post. Does anyone care to say how I could have found these invisible characters while debugging?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM