Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
given a string SSSEERRTADEEE write a program to output the following way to given string:S3E2R2T1A1D1E3


please what will be the logic to above probl C# in c#.Hope anyone must give me the solution...am waiting for your reply...
Posted

You can use the code below:

C#
private static void GetCharCountInString()
        {
            const string strOriginal = "SSSEERRTADEEE";
            string strNew = string.Empty;
            int index = 0;
            char[] chararray = strOriginal.ToCharArray();


            for (index = 0; index < chararray.Length; index++)
            {
                int charCount = 1;
                int firstindex = index;
                int flag = 0;

                while (index != strOriginal.Length - 1 & flag == 0)
                {
                    if (chararray[index].CompareTo(chararray[index + 1]) == 0)
                    {
                        charCount++;
                        index++;
                        flag = 0;
                    }
                    else
                    {
                        flag = 1;
                    }
                }

                strNew += chararray[firstindex].ToString(CultureInfo.InvariantCulture) +
                          charCount.ToString(CultureInfo.InvariantCulture);
            }

            Console.WriteLine("Original : {0}\n New : {1}", strOriginal, strNew);
        }


Happy Coding :)
 
Share this answer
 
Comments
Aurovinda shyamal 6-Feb-13 7:28am    
Hi SruthiR
This code is working fine.Thanks for your time given....
C#
string s = // ...

// ...

if (s == "SSSEERRTADEEE")
    s = "S3E2R2T1A1D1E3";

//... :-)


It should give you the following idea: if you provided some example of data on input and output, it does not mean you formulated the problem.

The question does not really make any sense.

Good luck,
—SA
 
Share this answer
 
Comments
Aurovinda shyamal 6-Feb-13 1:36am    
Hi Sergy
If you don't know the answer, please avoid,the question but don't give any negative comment about any one's question.Its my requirement..I need it... very urgent.
Sergey Alexandrovich Kryukov 6-Feb-13 1:45am    
It cannot be urgent, because you apparently don't know what you want. About negative comment... it's not even rude, just ignorant. My answer is accurate enough, you just fail to see it.
—SA
skydger 6-Feb-13 2:21am    
Fair enough.
My 5 xD
Sergey Alexandrovich Kryukov 6-Feb-13 2:23am    
Thank you. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900