Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi...
I have a string array. I want to delete duplicated elements from that array. How can I do that?

Please help me.
Posted
Updated 9-May-11 0:44am
v4
Comments
Sandeep Mewara 9-May-11 7:17am    
share your code/effort for the same. Use 'Improve question' link to edit/update the question.
Legor 9-May-11 7:30am    
Show what you've tried so far.
Olivier Levrey 9-May-11 8:00am    
Are you using STL? MFC? something else?

This solution is using linq:

C#
string[] input = new string[]{"one","two","tree","tree","one","four"};
input = input.ToList().Distinct().ToArray();
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-May-11 12:44pm    
Better. My 5.
--SA
Jijesh Balakrishnan 9-May-11 23:46pm    
thank you for your answer
try below link....

[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-May-11 12:44pm    
It will work, my 5. Even better -- keep data without duplicate in first place, use HashSet, Dictionary.
--SA
Jijesh Balakrishnan 9-May-11 23:46pm    
thank you for your answer
Try this,
CString StrArray;
StrArray.Add("aa");
StrArray.Add("bb");
StrArray.Add("cc");
bool flag =0 ;
CString NewStrToAdd = "dd"
for(int y = 0 ;y < StrArray.GetCount(); y++)
{
   if(NewStrToAdd == StrArray.ElementAt(y))
   {
      flag = 1;
      break;
   }
}
if(flag == 0)
{
   StrArray.Add(NewStrToAdd );
}
 
Share this answer
 
Comments
Jijesh Balakrishnan 9-May-11 23:47pm    
thank you for your answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900