Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. String iterations ....

String iterations ....

Scheduled Pinned Locked Moved C#
csharpoophelp
17 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nareshss
    wrote on last edited by
    #1

    Hi Every 1, Iam new to C# (Object Oriented Concepts ) i have a doubt lie this ------------ I want to Repeat a String ( Satish ) for 100 times with out using any loops , arrays n conditions .. Ex : Satish Satish Satish Satish Satish Satish Satish - - - - Satish Like this 100 times i need ... Plz help me ... Thanks in Advance ...

    H M R G 5 Replies Last reply
    0
    • N nareshss

      Hi Every 1, Iam new to C# (Object Oriented Concepts ) i have a doubt lie this ------------ I want to Repeat a String ( Satish ) for 100 times with out using any loops , arrays n conditions .. Ex : Satish Satish Satish Satish Satish Satish Satish - - - - Satish Like this 100 times i need ... Plz help me ... Thanks in Advance ...

      H Offline
      H Offline
      Harvey Saayman
      wrote on last edited by
      #2

      Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); - - - - - -Console.WriteLine("Satish");

      Harvey Saayman - South Africa Junior Developer .Net, C#, SQL think BIG and kick ASS

      you.suck = (you.passion != Programming)
      
      L 1 Reply Last reply
      0
      • N nareshss

        Hi Every 1, Iam new to C# (Object Oriented Concepts ) i have a doubt lie this ------------ I want to Repeat a String ( Satish ) for 100 times with out using any loops , arrays n conditions .. Ex : Satish Satish Satish Satish Satish Satish Satish - - - - Satish Like this 100 times i need ... Plz help me ... Thanks in Advance ...

        H Offline
        H Offline
        Harvey Saayman
        wrote on last edited by
        #3

        question... why no loops? whats the point of not using the "tools" a language offers?

        Harvey Saayman - South Africa Junior Developer .Net, C#, SQL think BIG and kick ASS

        you.suck = (you.passion != Programming)
        
        N P 2 Replies Last reply
        0
        • H Harvey Saayman

          Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); Console.WriteLine("Satish"); - - - - - -Console.WriteLine("Satish");

          Harvey Saayman - South Africa Junior Developer .Net, C#, SQL think BIG and kick ASS

          you.suck = (you.passion != Programming)
          
          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          HarveySaayman wrote:

          you.suck = (you.passion != Programming)

          This is more interesting. :-D

          He died when he was alive.

          H 1 Reply Last reply
          0
          • L Lost User

            HarveySaayman wrote:

            you.suck = (you.passion != Programming)

            This is more interesting. :-D

            He died when he was alive.

            H Offline
            H Offline
            Harvey Saayman
            wrote on last edited by
            #5

            haha, agreed!

            Harvey Saayman - South Africa Junior Developer .Net, C#, SQL think BIG and kick ASS

            you.suck = (you.passion != Programming)
            
            1 Reply Last reply
            0
            • H Harvey Saayman

              question... why no loops? whats the point of not using the "tools" a language offers?

              Harvey Saayman - South Africa Junior Developer .Net, C#, SQL think BIG and kick ASS

              you.suck = (you.passion != Programming)
              
              N Offline
              N Offline
              nareshss
              wrote on last edited by
              #6

              Thanq ... This is the Question i faced in an interview . Thats y am asking , is there any procedure to do it . thats all .... Thanq frnds ...

              H 1 Reply Last reply
              0
              • H Harvey Saayman

                question... why no loops? whats the point of not using the "tools" a language offers?

                Harvey Saayman - South Africa Junior Developer .Net, C#, SQL think BIG and kick ASS

                you.suck = (you.passion != Programming)
                
                P Offline
                P Offline
                phannon86
                wrote on last edited by
                #7

                Probably a homework assignment, that's usually what these types of questions are. e.g. Do this, but you're not allowed to use this".

                He who makes a beast out of himself gets rid of the pain of being a man

                1 Reply Last reply
                0
                • N nareshss

                  Thanq ... This is the Question i faced in an interview . Thats y am asking , is there any procedure to do it . thats all .... Thanq frnds ...

                  H Offline
                  H Offline
                  Harvey Saayman
                  wrote on last edited by
                  #8

                  what was your reply to the question?

                  Harvey Saayman - South Africa Junior Developer .Net, C#, SQL think BIG and kick ASS

                  you.suck = (you.passion != Programming)
                  
                  N 1 Reply Last reply
                  0
                  • N nareshss

                    Hi Every 1, Iam new to C# (Object Oriented Concepts ) i have a doubt lie this ------------ I want to Repeat a String ( Satish ) for 100 times with out using any loops , arrays n conditions .. Ex : Satish Satish Satish Satish Satish Satish Satish - - - - Satish Like this 100 times i need ... Plz help me ... Thanks in Advance ...

                    M Offline
                    M Offline
                    Maruf Maniruzzaman
                    wrote on last edited by
                    #9

                    Does following work? public static void printit(string value, int num) { if (num < 1) return; num--; Console.WriteLine(value); printit(value, num); } static void Main() { printit("Satish", 100); }

                    Maruf Maniruzzaman Dhaka, Bangladesh. Homepage: http://www.kuashaonline.com
                    Blog you should not miss Tomorrow is a blank page

                    R 1 Reply Last reply
                    0
                    • M Maruf Maniruzzaman

                      Does following work? public static void printit(string value, int num) { if (num < 1) return; num--; Console.WriteLine(value); printit(value, num); } static void Main() { printit("Satish", 100); }

                      Maruf Maniruzzaman Dhaka, Bangladesh. Homepage: http://www.kuashaonline.com
                      Blog you should not miss Tomorrow is a blank page

                      R Offline
                      R Offline
                      Roger Alsing 0
                      wrote on last edited by
                      #10

                      Functional style :-) Well there is a condition in it so Id say it doesnt live up to the OPs requirements.

                      Blog: http://www.rogeralsing.com Projects: http://www.puzzleframework.com

                      1 Reply Last reply
                      0
                      • H Harvey Saayman

                        what was your reply to the question?

                        Harvey Saayman - South Africa Junior Developer .Net, C#, SQL think BIG and kick ASS

                        you.suck = (you.passion != Programming)
                        
                        N Offline
                        N Offline
                        nareshss
                        wrote on last edited by
                        #11

                        By using "Console.WriteLine" is the answer for my question . He asked me the basic question but i thought that there is any other tech to implement like that .... Thats wat ... ok Thanq Saayman ....

                        J 1 Reply Last reply
                        0
                        • N nareshss

                          Hi Every 1, Iam new to C# (Object Oriented Concepts ) i have a doubt lie this ------------ I want to Repeat a String ( Satish ) for 100 times with out using any loops , arrays n conditions .. Ex : Satish Satish Satish Satish Satish Satish Satish - - - - Satish Like this 100 times i need ... Plz help me ... Thanks in Advance ...

                          R Offline
                          R Offline
                          Roger Alsing 0
                          wrote on last edited by
                          #12

                          C#3

                          string res = Enumerable
                          .Repeat("Satish", 100)
                          .Aggregate((left, right) => left + Environment.NewLine + right);

                          Console.WriteLine(res);

                          Do I get a cookie?

                          Blog: http://www.rogeralsing.com Projects: http://www.puzzleframework.com

                          M 1 Reply Last reply
                          0
                          • R Roger Alsing 0

                            C#3

                            string res = Enumerable
                            .Repeat("Satish", 100)
                            .Aggregate((left, right) => left + Environment.NewLine + right);

                            Console.WriteLine(res);

                            Do I get a cookie?

                            Blog: http://www.rogeralsing.com Projects: http://www.puzzleframework.com

                            M Offline
                            M Offline
                            Maruf Maniruzzaman
                            wrote on last edited by
                            #13

                            Enumerable maintains an array- am I right? ;P

                            Maruf Maniruzzaman Dhaka, Bangladesh. Homepage: http://www.kuashaonline.com
                            Blog you should not miss Tomorrow is a blank page

                            1 Reply Last reply
                            0
                            • N nareshss

                              Hi Every 1, Iam new to C# (Object Oriented Concepts ) i have a doubt lie this ------------ I want to Repeat a String ( Satish ) for 100 times with out using any loops , arrays n conditions .. Ex : Satish Satish Satish Satish Satish Satish Satish - - - - Satish Like this 100 times i need ... Plz help me ... Thanks in Advance ...

                              G Offline
                              G Offline
                              Guffa
                              wrote on last edited by
                              #14

                              nareshss wrote:

                              i have a doubt lie this

                              You mean a question? ;) 1.

                              Console.Write(new String('x',100).Replace("x","Satish\r\n"));

                              Console.Write("ssssssssss".Replace("s","ssssssssss").Replace("s","Satish\r\n"));

                              public string msg(int cnt) { return "Satish\r\n" + (cnt > 1 ? msg(cnt - 1) : string.Empty); }
                              Console.Write(msg(100));

                              Despite everything, the person most likely to be fooling you next is yourself.

                              modified on Monday, February 25, 2008 8:15 AM

                              M E 2 Replies Last reply
                              0
                              • G Guffa

                                nareshss wrote:

                                i have a doubt lie this

                                You mean a question? ;) 1.

                                Console.Write(new String('x',100).Replace("x","Satish\r\n"));

                                Console.Write("ssssssssss".Replace("s","ssssssssss").Replace("s","Satish\r\n"));

                                public string msg(int cnt) { return "Satish\r\n" + (cnt > 1 ? msg(cnt - 1) : string.Empty); }
                                Console.Write(msg(100));

                                Despite everything, the person most likely to be fooling you next is yourself.

                                modified on Monday, February 25, 2008 8:15 AM

                                M Offline
                                M Offline
                                Malcolm Smart
                                wrote on last edited by
                                #15

                                Guffa wrote:

                                Console.Write("ssssssssss".Replace("s","ssssssssss").Replace("s","Satish\r\n"));

                                Sheer genius. :laugh:

                                Knowledge is hereditary, it will find its way up or down. - Luc Pattyn
                                so you answer don't be scared of failure The only failure is never to try Things You've Never Done - Passenger -2008

                                1 Reply Last reply
                                0
                                • G Guffa

                                  nareshss wrote:

                                  i have a doubt lie this

                                  You mean a question? ;) 1.

                                  Console.Write(new String('x',100).Replace("x","Satish\r\n"));

                                  Console.Write("ssssssssss".Replace("s","ssssssssss").Replace("s","Satish\r\n"));

                                  public string msg(int cnt) { return "Satish\r\n" + (cnt > 1 ? msg(cnt - 1) : string.Empty); }
                                  Console.Write(msg(100));

                                  Despite everything, the person most likely to be fooling you next is yourself.

                                  modified on Monday, February 25, 2008 8:15 AM

                                  E Offline
                                  E Offline
                                  engsrini
                                  wrote on last edited by
                                  #16

                                  simply superb.. :)

                                  1 Reply Last reply
                                  0
                                  • N nareshss

                                    By using "Console.WriteLine" is the answer for my question . He asked me the basic question but i thought that there is any other tech to implement like that .... Thats wat ... ok Thanq Saayman ....

                                    J Offline
                                    J Offline
                                    JavedWahid
                                    wrote on last edited by
                                    #17

                                    what about a recursive function?

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • World
                                    • Users
                                    • Groups