I like Quintin Robinson's answer, only there should be some improvements, such as deleting the list, because in this case it is not necessary. In addition, in my opinion, the Uppercase char ("K") and the lowercase char ("k") are the same thing, so they should be considered the same.
So here is how I do it:
private static string RemoveDuplicates(string textEntered) { string newString = string.Empty; foreach (var c in textEntered) { if (newString.Contains(char.ToLower(c)) || newString.Contains(char.ToUpper(c))) { continue; } newString += c.ToString(); } return newString; }
Ričards Mauriņš
source share