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

Answers were Sorted based on User's Feedback



how can i return string by vilating duplicates(inpyt like asdfsda but output should be 2a2d2sf and..

Answer / 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

how can i return string by vilating duplicates(inpyt like asdfsda but output should be 2a2d2sf and..

Answer / hari

we can modify the previous answer to make it efficient...
check it..

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

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Sharp Interview Questions

What is hashtable in c# with example?

0 Answers  


What are native methods?

0 Answers  


What is a system lock?

0 Answers   KEN Group, Wipro,


What is string class in c#?

0 Answers  


What is response redirect in c#?

0 Answers  


what is IComparable

0 Answers   Wipro,


Is there throws keyword in c#?

0 Answers  


What is difference between constants and read-only?

0 Answers  


1)what is timestamp in C# (anilringole@gmail.com)

2 Answers   Wipro,


What’s a strong name?

0 Answers  


What is the use of New Keyword

15 Answers  


Where value types are stored in c#?

0 Answers  


Categories