How space function in C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ad

    How space function in C#

    Is there fucntion in C#, which will return a string consist of a given
    number of space, like

    Space(5)-> " ";



  • Jon Shemitz

    #2
    Re: How space function in C#

    ad wrote:
    [color=blue]
    > Is there fucntion in C#, which will return a string consist of a given
    > number of space, like
    >
    > Space(5)-> " ";[/color]

    new String(' ', 5)

    --

    Midnight Beach is Jon Shemitz, a freelance programmer and author. Jon offers software consulting and contract services, and recently finished his 2nd book - .NET 2.0 for Delphi Programmers.

    Comment

    • Mark R. Dawson

      #3
      RE: How space function in C#

      string strPadded = "".PadRight (5);

      "ad" wrote:
      [color=blue]
      > Is there fucntion in C#, which will return a string consist of a given
      > number of space, like
      >
      > Space(5)-> " ";
      >
      >
      >
      >[/color]

      Comment

      • Jon Skeet [C# MVP]

        #4
        RE: How space function in C#

        Mark R. Dawson <MarkRDawson@di scussions.micro soft.com> wrote:[color=blue]
        > string strPadded = "".PadRight (5);[/color]

        That will work, but I personally far prefer Jon Shemitz's solution -
        it's more readable, and it's very obvious how to go from that to a
        string of 5 tabs, say.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • Usenet User

          #5
          Re: How space function in C#

          On Sun, 21 Aug 2005 08:18:58 +0100, Jon Skeet [C# MVP]
          <skeet@pobox.co m> wrote:
          [color=blue]
          >Mark R. Dawson <MarkRDawson@di scussions.micro soft.com> wrote:[color=green]
          >> string strPadded = "".PadRight (5);[/color]
          >
          >That will work, but I personally far prefer Jon Shemitz's solution -
          >it's more readable, and it's very obvious how to go from that to a
          >string of 5 tabs, say.[/color]

          Well, you still can do the same with padding:

          "".PadRight ( 5, '\t' );

          But as of preference, I still agree with you :))

          Comment

          • Usenet User

            #6
            Re: How space function in C#

            On Sun, 21 Aug 2005 08:18:58 +0100, Jon Skeet [C# MVP]
            <skeet@pobox.co m> wrote:
            [color=blue]
            >Mark R. Dawson <MarkRDawson@di scussions.micro soft.com> wrote:[color=green]
            >> string strPadded = "".PadRight (5);[/color]
            >
            >That will work, but I personally far prefer Jon Shemitz's solution -
            >it's more readable, and it's very obvious how to go from that to a
            >string of 5 tabs, say.[/color]

            Well, you still can do the same with padding:

            "".PadRight ( 5, '\t' );

            But as of preference, I still agree with you :))

            Comment

            Working...