我有一个文本框,每个项目都在一个新行上。我正在尝试从此文本框中删除重复项。我什么都想不出来。我尝试将每个项目添加到数组中并删除重复项,但它不起作用。还有其他选择吗?
3471 次
3 回答
7
yourTextBox.Text = string.Join(Environment.NewLine, yourArray.Distinct());
于 2011-01-01T02:26:45.560 回答
4
基于 Anthony Pegram 所写的内容,但不需要单独的数组:
yourTextBox.Text = string.Join(Environment.NewLine, yourTextBox.Lines.Distinct());
于 2011-01-05T18:04:16.027 回答
1
将所有项目添加到字符串数组并使用此代码删除重复项
public static string[] RemoveDuplicates(string[] s)
{
HashSet<string> set = new HashSet<string>(s);
string[] result = new string[set.Count];
set.CopyTo(result);
return result;
}
有关更多信息,请查看 从数组中删除重复项
于 2011-01-01T02:27:53.093 回答