6
Answers

convert "aaabbccc" to "3a2b3c" by using c#

Raja A

Raja A

9y
362
1
Can anyone tell me how to  convert "aaabbccc" to "3a2b3c" using c#... 
Answers (6)
1
Upendra Pratap Shahi

Upendra Pratap Shahi

NA 13.3k 861.3k 9y
Hello ,
 
Use below code-
 

protected void countOccurance()

{

string input = "aaabbccc";

Dictionary<string, int> objdict = new Dictionary<string, int>();

foreach (char j in input)

{

if (objdict.ContainsKey(j.ToString()))

{

objdict[j.ToString()] = objdict[j.ToString()] + 1;

}

else

{

objdict.Add(j.ToString(), 1);

}

}

foreach (var temp in objdict)

{

Response.Write( temp.Value+temp.Key);

}

}

 output-  3a2b3c
 
If this helped you kindly accept the answer
 
 
Accepted
0
Upendra Pratap Shahi

Upendra Pratap Shahi

NA 13.3k 861.3k 9y
Your welcome Raja A, If this helped you kindly accept the answer for better discussion on forum.
Accepted
0
Upendra Pratap Shahi

Upendra Pratap Shahi

NA 13.3k 861.3k 9y
Thanks Raja A for appreciation, I've tried to provide a code as per your requirement. Kindly wait for this.
0
Upendra Pratap Shahi

Upendra Pratap Shahi

NA 13.3k 861.3k 9y
Hello Raja A, As mentioned you in your question I've provide a code according to your need which mention in question. According to your requirement this answer is correct. Accept the Answer and start a new thread for your new requirement. If you want another output from here then kindly mention desired output in question every time.
0
Raja A

Raja A

NA 142 11.6k 9y
Thank you very much Upendra. But i need aaabbcccaabb = 3a2b3c2a2b like this
0
Raja A

Raja A

NA 142 11.6k 9y
Thank you very much Upendra. But i need aaabbcccaabb = 3a2b3c2a2b like this