Remove Duplicate Records from a string
public string RemoveDuplicates(string items)
{
StringBuilder Result = new StringBuilder();
String[] newArray = items.Split(',');
for (int i = 0; i < newArray.Length; i++)
{
if (Result.ToString().IndexOf(newArray[i]) == -1)
{
Result.Append(newArray[i].ToString()).Append(",");
}
}
return Result.ToString().Substring(0, Result.ToString().LastIndexOf(','));
}
EXample : Value=Apple, Banana,Cherry, Apple,Banana
Value=RemoveDuplicates(Value);
Result: Apple, Banana, Cherry
No comments:
Post a Comment