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
Explain About Postback
How many bytes is an int in c#?
What are console applications used for?
What is private void in c#?
What is whitespace in c#?
Can an abstract class inherit from another abstract class c#?
Explain static class members.
What is the difference between abstract class and interface in c#?
To allow an element to be accessed using a unique key which .NET collection class is used ?
What is a helper method in c#?
What is the purpose of namespace in c#?
How do you declare a variable in c#?
What is anonymous class in c#?
Can you inherit multiple classes in c#?
How do I calculate relative time?