【问题标题】:String retrieved as shell32 GetDetailsOf never '=='s hard coded string that appear the same. Unable to parse with DateTime.Parse作为 shell32 GetDetailsOf 检索的字符串从不 '==' 看起来相同的硬编码字符串。无法使用 DateTime.Parse 解析
【发布时间】:2014-10-02 15:47:13
【问题描述】:

我的真正目标是 DateTime.Parse 从 Shell32 GetDetailsOf 扩展日期字段中的日期字符串。 在进一步调试时,我只是创建了一个看起来相同的字符串,并且 DateTime 能够解析它。当我在内存中查看 2 个字符串时,它们看起来不同。

仅前几个字节.....

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

有没有办法格式化字符串,以便我能够用 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++;
            }
        }

【问题讨论】:

  • 如果第一行失败,你怎么知道第二行解析正确?
  • 公平的问题,但我实际上只是在运行时间之前更改了变量。当我发布问题时,我复制了该行并按错误的顺序放置...我将更新原始帖子,以免让其他人失望。

标签: c# datetime shell32


【解决方案1】:

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

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

我从昨天晚上开始一直在搜索,当我最终发布问题时,我在 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。有谁愿意说我在调试时如何找到这些不可见的字符?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 2018-07-01
    • 2015-02-04
    • 1970-01-01
    • 2019-05-20
    相关资源
    最近更新 更多