C# 字符串检索为shell32 GetDetailsOf never'==';s显示相同的硬编码字符串。无法使用DateTime进行分析。请分析
我真正的目标是DateTime。解析Shell32 GetDetailsOf扩展日期字段中的日期字符串。 在进一步调试的过程中,我只创建了一个看起来相同的字符串,DateTime可以解析它。当我查看内存中的两个字符串时,它们看起来不同 仅前几个字节 s>4c 22 2e 63 16 00 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解析它C# 字符串检索为shell32 GetDetailsOf never'==';s显示相同的硬编码字符串。无法使用DateTime进行分析。请分析,c#,datetime,shell32,C#,Datetime,Shell32,我真正的目标是DateTime。解析Shell32 GetDetailsOf扩展日期字段中的日期字符串。 在进一步调试的过程中,我只创建了一个看起来相同的字符串,DateTime可以解析它。当我查看内存中的两个字符串时,它们看起来不同 仅前几个字节 s>4c 22 2e 63 16 00 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 有没有一
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++;
}
}
呃,我在这里找到了答案
我从昨天晚上开始一直在搜索,当我最终发布问题时,我在30分钟内找到了答案
显然,字符(char)8206(char)8207存在于GetDetailsOf的字符串s中。当我使用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,从而找到了字符8206和8207。有人想说我是如何在调试时发现这些不可见的字符的吗?如果第二行在第一行失败,你怎么知道第二行会正确解析?这是一个公平的问题,但实际上我只是在运行时之前更改了变量。当我发布问题时,我复制了这一行,并将其按错误的顺序排列。。。我会更新原来的帖子,以免把别人甩了。