Hi I have a text box that has values separated by a comma. I am trying to remove the duplicate values for, example this text box will have values like:
SO-001, SO-003, SO-002, SO-001, SO-001
To return unique values like:
SO-001, SO-003, SO-002
Use this Function it
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(',')); }
To Call this Function Like this...
textbox1.Text=RemoveDuplicates(textbox1.Text);
No comments:
Post a Comment