Assuming the format of this line:
var theString = "smith:rodgers:someone:smith:white"; var subStrings = theString.Split(new char[] { ':' }); var uniqueEntries = new List<string>(); foreach(var item in subStrings) { if (!uniqueEntries.Contains(item)) { uniqueEntries.Add(item); } } var uniquifiedStringBuilder = new StringBuilder(); foreach(var item in uniqueEntries) { uniquifiedStringBuilder.AppendFormat("{0}:", item); } var uniqueString = uniquifiedStringBuilder.ToString().Substring(0, uniquifiedStringBuilder.Length - 1);
Very long, but shows the process of transition from one to another.
source share