Hey!
I have a problem.. I need to remove items from array that are duplicated here's my code:
private void Form2_Load(object sender, EventArgs e)
{
openFileDialog1.Title = "Open Links List";
openFileDialog1.Filter = "Text File|*.txt";
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
var file = openFileDialog1.FileName;
if (file != "")
{
StreamReader read = new StreamReader(file);
var items = read.ReadToEnd();
string[] urls = items.Split('\n');
var url = RemoveDups(urls);
read.Close();
//StreamWriter write = new StreamWriter(file);
foreach (string i in urls)
{
//write.WriteLine(i);
MessageBox.Show(i);
}
//write.Close();
/*StreamWriter writer = new StreamWriter(file);
string currentLine;
HashSet<string> previousLines = new HashSet<string>();
while ((currentLine = read.ReadLine()) != null)
{
if (previousLines.Add(currentLine))
{
writer.WriteLine(currentLine);
}
}*/
}
}
public string[] RemoveDups(string[] s)
{
var count = s.Count();
string[] arr = new String[count];
for (int i = 0; i < count; i++)
{
if (!arr.Contains(s[i]))
{
arr[i] = s[i];
}
}
return arr;
}
Somehow it doesnt work