Remove duplicate character from string without using inbuilt function.

Hello,
Below program is for remove duplicate characters from given string. you can see that I have given string name as "hemanshu goswami". in that string duplicate characters are like 'h','m','a','s' and etc. so at the end you will be see output as "hemansu gowi". means that if any duplicate character will come, this program will allow it to display it again. hope you can enjoy and understand it.

class Program
    {
        static void Main(string[] args)
        {
            string s = "hemanshu goswami";
            string final = "";
            foreach (char c in s)
            {
                if(string.IsNullOrEmpty(final) || !final.Contains(c)) //check if final string contains any existing character or not.
                {
                    final += c;
                }
            }
            Console.Write(final);
            Console.ReadLine();
 }

output:hemanshu gowi

No comments:

Post a Comment

Please let me know if you have any feedback or doubts.

Jagged Array

What is Jagged Array? Jagged array is called as "array of arrays". when you need a data inside your array element at that time you...