Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

De-duplicate and Sort Alphabetically

Description
This macro will take a comma separated list, de-duplicate the values, and then sort them alphabetically with one value on each line.
For example, the following input:
    Apples, Pears, Bananas, Apples, Oranges, Pears
Would produce the following output:
    Apples
    Bananas
    Oranges
    Pears
Language
C#.net
Minimum Version
Created By
Jon Tackabury (BFS)
Contributors
-
Date Created
Aug 19, 2014
Date Last Modified
Aug 19, 2014

Macro Code

using System;
using System.IO;
using System.Collections.Generic;

public static class ClipboardFusionHelper
{
        public static string ProcessText(string text)
        {
                List<string> oItems = new List<String>();

                StringReader sr = new StringReader(text);
                string line;
                line= sr.ReadLine();
                while (line != null)
                {
                        string[] parts = line.Split(',');
                        foreach (string strPart in parts) {
                                string strNewPart = strPart.Trim();
                                if (!oItems.Contains(strNewPart )) {
                                        oItems.Add(strNewPart );
                                }
                        }
                        line = sr.ReadLine();
                }
                oItems.Sort();
                return String.Join("\n", oItems.ToArray());
        }
}