Wednesday, October 5, 2022
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’ll study The 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 Applications 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 evaluate the characters in any other case capital characters and small alphabetical characters will probably 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 clever Uppercase and
lowercase will probably be thought-about as distinction character

inputString =
inputString.ToLower();

//outcome for holding the distinct
characters

string outcome = string.Empty;

//Loop by means of every character of
the string

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

{

   
//If character shouldn’t be added (comprises) within the outcome variable, Add it
to the outcome string

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

   
{

        outcome += inputString[i];

   
}

}

//Present the ultimate outcome to the
consumer

Console.WriteLine(outcome);

//Console.ReadLine() to carry the
display 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