how can i return string by vilating duplicates(inpyt like
asdfsda but output should be 2a2d2sf and 2a,2d,2s,f)

Answer Posted / adityakiran

I suppose this question is intended to test the knowledge on
IEnumerator. The following piece of code may give the
required first part of the output...

string x = "asdfsdaaasasa";
string output = "";
int count = 0;
IEnumerator ie = x.GetEnumerator();
IEnumerator iee = x.GetEnumerator();
while(ie.MoveNext())
{
while(iee.MoveNext())
{
if ((char)ie.Current == (char)iee.Current)
{
count++;
}
}
iee.Reset();
if (!output.Contains(ie.Current.ToString()))
output = output + count + ie.Current;
count = 0;
}
Console.WriteLine(output);

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain About Postback

724


What is data annotation in c#?

679


Which language is used for desktop application?

671


If a method's return type is void, can you use a return keyword in the method?

691


Is c# code is managed or unmanaged code?

655


How big is an int16?

663


Define thread?

749


Perfect Example Of While And Do-While Loop In C#.Net ?

746


How many types of interface are there in c#?

685


What is class method c#?

668


Explain how to parse a datetime string?

669


What is an assembly in .net?

746


How do I do a case-insensitive string comparison?

692


Can an abstract class inherit from another abstract class c#?

719


Difference between debug.write and trace.write?

724