Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove duplicates from a TextBox?

I have a text box that has each item on a new line. I am trying to remove duplicates from this textBox. I can't think of anything. I tried adding each item to an array and the removing the duplicates, but it doesn't work. Are there any other options?

like image 659
Jeremy Avatar asked Jan 01 '11 02:01

Jeremy


2 Answers

yourTextBox.Text = string.Join(Environment.NewLine, yourArray.Distinct());
like image 200
Anthony Pegram Avatar answered Sep 27 '22 21:09

Anthony Pegram


Building on what Anthony Pegram wrote, but without needing a separate array:

yourTextBox.Text = string.Join(Environment.NewLine, yourTextBox.Lines.Distinct());

like image 33
CSharper Avatar answered Sep 27 '22 21:09

CSharper