【发布时间】:2014-11-17 20:05:57
【问题描述】:
我有一个字符串[],其中填充了来自日志文件的错误消息。 现在我需要将它们相互比较,因为很多错误是相同的。 然后我需要返回它们,以便使用正则表达式过滤整个日志文件。
这是我的代码:
foreach (string item in errSplit)
{
string[] lines = item.Split(new string[] {"\r\n", "\n"}, StringSplitOptions.None);
fisrt = lines.FirstOrDefault();
// Here I woud like to loop thru the sring and compare the values
// and save the string,so every error exists just onece
fehler.WriteLine(fisrt);
}
这就是字符串看起来正确的方式知道:
Services.Exceptions.Exceptions - 系统...
Services.Exceptions.Exceptions - 系统...
Services.Exceptions.Exceptions - ~/Default...
【问题讨论】:
-
Enumerable.Distinct怎么样?如果 string 项完全匹配,则返回yourArray.Distinct().ToArray() -
如果您使用HashSet<T> 而不是
string[],它将自动为您解决问题。