我有一个文本框,每个项目都在新行上。我正在尝试从此textBox中删除重复项。我什么也想不出来。我尝试将每一项添加到数组中,并删除重复项,但不起作用。还有没有别的选择?
发布于 2011-01-01 02:26:46
yourTextBox.Text = string.Join(Environment.NewLine, yourArray.Distinct());
发布于 2011-01-05 18:04:16
建立在Anthony Pegram写的基础上,但不需要单独的数组:
yourTextBox.Text = string.Join(Environment.NewLine, yourTextBox.Lines.Distinct());
发布于 2011-01-01 02:27:53
将所有项添加到字符串数组中,并使用此代码删除重复项
public static string[] RemoveDuplicates(string[] s)
{
HashSet<string> set = new HashSet<string>(s);
string[] result = new string[set.Count];
set.CopyTo(result);
return result;
}
有关更多信息,请查看Remove duplicates from array
https://stackoverflow.com/questions/4572987
复制