Dear Brother's
I want to remove all same values from my string array. Please help me regarding this.. I am waiting for good response. Thanks in advance.
Best regards
Waqar Hussain laghari
Dear Brother's
I want to remove all same values from my string array. Please help me regarding this.. I am waiting for good response. Thanks in advance.
Best regards
Waqar Hussain laghari
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sudhakar EggojiPosted Mar 30, 2009, 6:29 AM
Sample code for removing duplicates from String array.
public string[] removeDuplicates(string[] strArray) myList= new List() ;
{
List
int i,j,count;
for (i = 0; i < strArray.Length; i++)
{
count = 0;
for (j = i; j < strArray.Length; j++)
{
if (strArray[i] == strArray[j])
count++;
}
if (count == 1)
{
myList.Add(strArray[i]);
}
}
return myList.ToArray();
}
Regards,
Sudhakar
waqar laghariPosted Mar 30, 2009, 7:46 AM
thanks brother's..
I like both answers but i use the second one. Thanks.
Best regards
Waqar Hussain Laghari
akhilPosted Mar 30, 2009, 6:29 AM
use following code to solve ur problem
string [] s=new string[5];
StringBuilder sTmp=new StringBuilder();
// u can store data according to ur need here i just used sample data
s[0]="hello";
s[1]="hi";
s[2]="hello";
s[3]="hi";
s[4]="done";
IEnumerator oEnum= s.GetEnumerator( );
while (oEnum.MoveNext())
{
if(!sTmp.ToString().Contains(oEnum.Current.ToString()))
{
sTmp.Append(oEnum.Current + "|");
}
}
string sT=sTmp.ToString().Trim('|');
s=null;
s=sT.Split('|');
// this is just for showing what is there now in string array u may omit this
for(int i=0;i
Console.WriteLine(s[i]);
}