alignment of strings representing integers

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

    alignment of strings representing integers

    I try to add strings with fixed length who are representing integers
    So I have to put spaces (I guesse) before short strings(from short
    integers).

    F.e.
    12345
    1
    567
    5432
    54328

    I am convinced that I can find a methode but I guesse that there must be
    a simple method given by VB.NET but that I don't know.
    Thanks for any response
  • Patrice

    #2
    Re: alignment of strings representing integers

    Try :
    Returns a new string of a specified length in which the beginning of the current string is padded with spaces or with a specified Unicode character.


    but what you are trying to do is unclear ("add strings" ?). It will allow to
    add spaces in front of your strings...

    If you want to add the numeric value representing those strings, you have to
    convert them and some of those values are not short integers which could be
    the problem you have ?

    --
    Patrice

    "andrews" <andrews@pandor a.bea écrit dans le message de groupe de
    discussion : 4gtsk.38403$qm2 .30502@newsfe13 .ams2...
    I try to add strings with fixed length who are representing integers
    So I have to put spaces (I guesse) before short strings(from short
    integers).
    >
    F.e.
    12345
    1
    567
    5432
    54328
    >
    I am convinced that I can find a methode but I guesse that there must be a
    simple method given by VB.NET but that I don't know.
    Thanks for any response

    Comment

    • andrews

      #3
      Re: alignment of strings representing integers

      I was thinking to be clear but here is the information

      dim Number as integer
      dim str1 as string = "Value is "
      dim st as string
      Number = 342
      st = str1 & Number.tostring

      Comment

      • Gillard

        #4
        Re: alignment of strings representing integers

        if you want your numbers to be represented like columns just use a textbox
        like this

        Dim r As New Random
        With TextBox1
        .RightToLeft = Windows.Forms.R ightToLeft.Yes
        .Multiline = True
        .Dock = DockStyle.Fill
        End With
        For x = 0 To 100
        TextBox1.Append Text(r.Next(0, 123456) & vbCrLf)
        Next


        "andrews" <andrews@pandor a.bewrote in message
        news:h2vsk.1555 32$ah4.55124@ne wsfe15.ams2...
        I was thinking to be clear but here is the information
        >
        dim Number as integer
        dim str1 as string = "Value is "
        dim st as string
        Number = 342
        st = str1 & Number.tostring

        Comment

        • Patrice

          #5
          Re: alignment of strings representing integers

          So it looks like the PadLeft solution could be what you are looking for.
          What if you try :

          Dim Number As Integer() = {1, 100, 80}
          Dim str1 As String = "Value is "
          For i = 0 To UBound(Number)
          Debug.WriteLine (str1 & Number(i).ToStr ing.PadLeft(10) )
          Next

          Is this what you are looking for ? If nopt, what is the difference wiht what
          you would like to get ???

          --
          Patrice

          "andrews" <andrews@pandor a.bea écrit dans le message de groupe de
          discussion : h2vsk.155532$ah 4.55124@newsfe1 5.ams2...
          I was thinking to be clear but here is the information
          >
          dim Number as integer
          dim str1 as string = "Value is "
          dim st as string
          Number = 342
          st = str1 & Number.tostring

          Comment

          • andrews

            #6
            Re: alignment of strings representing integers

            Padleft is for me THE SOLUTION that is the most simplest
            Thanks very much to everyone

            Comment

            • Phill W.

              #7
              Re: alignment of strings representing integers

              andrews wrote:
              I try to add strings with fixed length who are representing integers
              I am convinced that I can find a methode but I guesse that there must be
              a simple method given by VB.NET but that I don't know.
              How about this:

              Dim i as Integer = 77

              ? String.Format(" ({0,5})", i)
              ( 77)

              HTH,
              Phill W.

              Comment

              Working...