Wednesday, 28 May 2014

Remove Duplicate Records from a string


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

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...