Wednesday, 13 November 2013

Return unique values

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

SQL SERVER – Disk Space Monitoring – Detecting Low Disk Space on Server

CREATE PROCEDURE [CSMSDVLP].[DiskSpaceMonitor] @mailProfile nvarchar(500), @mailto nvarchar(4000), @threshold INT, @logfile nvarchar(40...