How can you remove duplicate characters in a string?

前端 未结 20 2240
离开以前
离开以前 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 17:07

    Below is the code to remove duplicate chars from a string

            var input = "SaaSingeshe";
            var filteredString = new StringBuilder();
            foreach(char c in input)
            {
                if(filteredString.ToString().IndexOf(c)==-1)
                {
                    filteredString.Append(c);
                }
            }
            Console.WriteLine(filteredString);
            Console.ReadKey();
    

提交回复
热议问题