Reputation: 117
i have let's say this richtextbox
teddyinwonderland
KristinaAlex33
MariamPetkova
VladislavMladenov
Odanessy
tvatieigrata
VaninaDimova
LillyRadevaa
disbalanced
AdriyanMinchev
vampirelove
blqblqlq
jakitoo
AdriyanMinchev
LillyRadevaa
ToshkoPulov
MaqGeorgieva
katiiig
NataliaNikolova393
Mila1305
pyfpafpyfpaf
GabriiellaDobreWa
galiinkaa
paffwinchester06
AlexFlip
iskocetegi
AdriyanMinchev
LillyRadevaa
ToshkoPulov
MaqGeorgieva
katiiig
NataliaNikolova393
Mila1305
pyfpafpyfpaf
GabriiellaDobreWa
galiinkaa
paffwinchester06
AlexFlip
iskocetegi
AdriyanMinchev
LillyRadevaa
ToshkoPulov
MaqGeorgieva
katiiig
NataliaNikolova393
Mila1305
pyfpafpyfpaf
GabriiellaDobreWa
galiinkaa
paffwinchester06
AlexFlip
iskocetegi
AchyyWee
simeonov91
DavidWilla
teddyinwonderland
katiiig
VladislavMladenov
AtanasVirishapkov
yeahhx
MartinaPetrowa855
GizemYasinAlaca
IOANAAAAA
yonii9
Odanessy
AchyyWee
simeonov91
DavidWilla
teddyinwonderland
katiiig
VladislavMladenov
AtanasVirishapkov
yeahhx
MartinaPetrowa855
GizemYasinAlaca
IOANAAAAA
yonii9
Odanessy
AchyyWee
simeonov91
DavidWilla
teddyinwonderland
katiiig
VladislavMladenov
AtanasVirishapkov
yeahhx
MartinaPetrowa855
GizemYasinAlaca
IOANAAAAA
yonii9
Odanessy
AchyyWee
simeonov91
DavidWilla
teddyinwonderland
katiiig
VladislavMladenov
AtanasVirishapkov
yeahhx
MartinaPetrowa855
GizemYasinAlaca
IOANAAAAA
yonii9
Odanessy
I want to remove the duplicates but i can not figure out how.
I tried with
var asd = richtextbox1.Text.Distinct().ToList()/ToArray();
foreach (string s in asd)
{
richtextbox1.text = richtextbox1.text + s;
}
Tried some other pointless things but nothing helped, from this one i am getting some weird results.
Upvotes: 0
Views: 900
Reputation: 11201
I would suggest you do richtextbox1.Lines.Distinct().ToArray()
and then assign it back
Upvotes: 2
Reputation: 53593
This will get you a List<string>
of distinct values:
var distinctItems = richTextBox1.Lines.Distinct().ToList();
Notice we're using the Lines
property of your RichTextBox. The Lines
property returns the contents of your RichTextBox as an array of strings with each line as an element in the array.
Upvotes: 2
Reputation: 24078
When you to .Text
, you get the whole text in a string, not a list of words. Split the words up first and then .Distinct()
will work.
You could have noticed this simply by stepping through your code in the debugger.
Upvotes: 0