Tuesday, September 22, 2026
HomeC#Program to take away the duplicate character from the string ~ IT...

Program to take away the duplicate character from the string ~ IT Tutorials with Instance


On this program, we are going to study The right way to take away the duplicate character from the string in C#.

I’ll suggest you to verify the beneath hyperlink for Prime C# Interview Packages requested through the Interview and Examination.

Program to take away the duplicate character from the string

As C# within the case-sensitive language, I’m changing the string to the lowercase string in order that I can examine the characters in any other case capital characters and small alphabetical characters can be handled as completely different characters.

Program to take away the duplicate character from the string in C# in talked about beneath:

Console.WriteLine(“Enter a string to take away duplicate character from
it:”
);

//Obtain enter from the consumer

string inputString = Console.ReadLine();

//Changing the inputString to
lowercase

//different sensible Uppercase and
lowercase can be thought of as distinction character

inputString =
inputString.ToLower();

//consequence for holding the distinct
characters

string consequence = string.Empty;

//Loop via every character of
the string

for (int i = 0; i < inputString.Size;
i++)

{

   
//If character is just not added (accommodates) within the consequence variable, Add it
to the consequence string

   
if
(!consequence.Accommodates(inputString[i]))

   
{

        consequence += inputString[i];

   
}

}

//Present the ultimate consequence to the
consumer

Console.WriteLine(consequence);

//Console.ReadLine() to carry the
display screen after the execution of this system

Console.ReadLine();

Output:

I hope this instance will assist in your interview/examination preparation.

Thanks

Protected by Copyscape - Do not copy content from this page.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments