How can you remove duplicate characters in a string?

前端 未结 20 2265
离开以前
离开以前 2020-12-05 16:39

I have to implements a function that takes a string as an input and finds the non-duplicate character from this string.

So an an example is if I pass string str = \"

20条回答
  •  再見小時候
    2020-12-05 16:56

    // Remove both upper-lower duplicates

    public static string RemoveDuplicates(string key)
        {
            string Result = string.Empty;
            foreach (char a in key)
            {
                if (Result.Contains(a.ToString().ToUpper()) || Result.Contains(a.ToString().ToLower()))
                    continue;
                Result += a.ToString();
            }
            return Result;
        }
    

提交回复
热议问题