How to Remove Duplicate characters from String in C#

Hello All,
In this Program, I will show you, how to make a program to remove duplicate characters from strings using c#

using System;
using System.Collections.Generic;

namespace testconsole

{
    class Program
    {
        static void Main(string[] args)
        {
            string Stringvalue = "this is Apple";
            string result = "";
            Console.WriteLine("Before remove duplicate character :{0} ", Stringvalue);

            foreach (char ch in Stringvalue)
            {
                if(result.Contains(ch.ToString()))
                {
                   
                }
                else
                {
                    result = result + ch;
                }
            }
            Console.WriteLine("after remove duplicate character :{0} ", result);
            Console.ReadKey();
        }

     
       
    }

}


Comments

Popular posts from this blog

Bootstrap Modal Popup keep open on PostBack in ASP.Net

Resolved Issue in Asp core 3.0 serializersettings does not exist in AddJsonOptions

.Net most asked interview questions for experienced professionals (C#,Asp WEBFORM,MVC,ASP CORE,WEB API,SQL Server,Java Script,Jquery)