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. ok, now how do i add six " " into a string by multiplying it

ok, now how do i add six " " into a string by multiplying it

Scheduled Pinned Locked Moved C#
questiontutorial
9 Posts 7 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
    NZSmartie
    wrote on last edited by
    #1

    hey, how can i add six " " (white spaces) into a string by doing it like " " * 6; six is just an example, because the number will change... thanks

    P Q V G R 6 Replies Last reply
    0
    • N NZSmartie

      hey, how can i add six " " (white spaces) into a string by doing it like " " * 6; six is just an example, because the number will change... thanks

      P Offline
      P Offline
      Parwej Ahamad
      wrote on last edited by
      #2

      plz try it.......... Dim s As New System.Text.StringBuilder s.Append("a") s.Append(" ", CountNumber) s.Append("b")

      Parwej Back...............DON of Developer....... Parwej Ahamad g_parwez@rediffmail.com

      N 1 Reply Last reply
      0
      • P Parwej Ahamad

        plz try it.......... Dim s As New System.Text.StringBuilder s.Append("a") s.Append(" ", CountNumber) s.Append("b")

        Parwej Back...............DON of Developer....... Parwej Ahamad g_parwez@rediffmail.com

        N Offline
        N Offline
        NZSmartie
        wrote on last edited by
        #3

        errr, this is C# I'm talking about not vb ;P

        P 1 Reply Last reply
        0
        • N NZSmartie

          hey, how can i add six " " (white spaces) into a string by doing it like " " * 6; six is just an example, because the number will change... thanks

          Q Offline
          Q Offline
          quiteSmart
          wrote on last edited by
          #4

          Roman957 wrote:

          add six " " (white spaces) into a string by doing it like " " * 6

          ofcourse no " " is not a number so you can not multiply it by 6 you can use a for loop //identify the number of spaces you want by assigning it to count int count = 6; String str; for( int i = 0; i < count; i++) { str += " "; }

          1 Reply Last reply
          0
          • N NZSmartie

            errr, this is C# I'm talking about not vb ;P

            P Offline
            P Offline
            Parwej Ahamad
            wrote on last edited by
            #5

            try.......... System.Text.StringBuilder s=new System.Text.StringBuilder(); s.Append("a"); s.Append(" ", CountNumber); s.Append("b");

            Parwej Back...............DON of Developer....... Parwej Ahamad g_parwez@rediffmail.com

            1 Reply Last reply
            0
            • N NZSmartie

              hey, how can i add six " " (white spaces) into a string by doing it like " " * 6; six is just an example, because the number will change... thanks

              V Offline
              V Offline
              Vega02
              wrote on last edited by
              #6

              String.PadRight[^] So it'll be something like str = str.PadRight(str.Length + 6).

              1 Reply Last reply
              0
              • N NZSmartie

                hey, how can i add six " " (white spaces) into a string by doing it like " " * 6; six is just an example, because the number will change... thanks

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

                There is a constructor for the string class that you can use: int count = 6; string spaces = new String(' ', count);

                --- Year happy = new Year(2007);

                1 Reply Last reply
                0
                • N NZSmartie

                  hey, how can i add six " " (white spaces) into a string by doing it like " " * 6; six is just an example, because the number will change... thanks

                  R Offline
                  R Offline
                  Russell Jones
                  wrote on last edited by
                  #8

                  you could create a FakeString class. add implicit casts between FakeString and String and also overload String * int, string *long. not forgetting to overload int * String and long * String. It doesn't sound worth it in this instance but if " " was of type vector for instance, it might well be. Russ

                  1 Reply Last reply
                  0
                  • N NZSmartie

                    hey, how can i add six " " (white spaces) into a string by doing it like " " * 6; six is just an example, because the number will change... thanks

                    S Offline
                    S Offline
                    Syed Muhammad Kamran
                    wrote on last edited by
                    #9

                    int count = 6; char space = ' '; StringBuilder st = new StringBuilder("Your String"); st.Append(space, count);

                    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