0

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++;
            }
        }
4

1 回答 1

2

如何从视频文件的“媒体创建”列中提取日期?

嗯,我在这里找到了答案..

我从昨天晚上开始一直在搜索,当我最终发布问题时,我在 30 分钟内找到了答案。

显然GetDetailsOf的字符串s中存在字符(char)8206 (char)8207。当我 MessageBox.Show() 时,这些字符看起来不可见,但删除它们解决了我的问题。

 // 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();

我知道 == 和 String.Equals 之间的区别。但我专门使用 == 来调试问题。

我通过在另一篇文章的帮助下尝试删除它们找到了字符 8206 和 8207。有谁愿意说我在调试时如何找到这些不可见的字符?

于 2014-10-02T16:20:28.627 回答