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 void in c#?

0 Answers  


how to return morethan one value using out parameter in c#.net ; For Example : public int show(out int []a) { int []a={1,2,3,4,5}; return a[]; } we have to print all the values without using the Console.WriteLine statement;

1 Answers   Verizon,


What are the differences between system.string and system.text.stringbuilder classes?

0 Answers  


Why do we Need of static class in c#?

0 Answers   NA,


List down the different ide’s provided by microsoft for c# development.

0 Answers  






Why do we need to override in c#?

0 Answers  


What is private and shared assembly?

0 Answers  


What is console readkey ()?

0 Answers  


Do loops in c#?

0 Answers  


what's the Difference between DataView and DataTable?

10 Answers  


explain synchronous and asynchronous in C#

3 Answers   AxSys, Mastek, Synechron,


What is xml serialization in c#?

0 Answers  


Categories