Click here to Skip to main content
12,078,298 members (47,634 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: string
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 5-Feb-13 18:13pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You can use the code below:

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 Smile | :)
  Permalink  
Comments
Aurovinda shyamal 6-Feb-13 7:28am
   
Hi SruthiR
This code is working fine.Thanks for your time given....
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
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.
   
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
   
Thank you. :-)
—SA

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160212.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100