limiting number of characters - pad

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

    #1

    limiting number of characters - pad

    Thanks in advance... I have a string that I'm building that needs to
    write to a file the last name, first name and middle initial in this
    format with a maximum of 20 characters. Two examples:

    Brenda J Lanier
    Lanier,Brenda J

    ' note that this name is only 15 characters, with the space and
    comma, after formatting so I'm safe

    Edward M Berksweller:
    Berksweller,Gar rett M

    ' note that this name has 21 characters, with the space and comma,
    so to stay within the 20 char limit it needs to write as:
    Berksweller,Gar rett
    with the space being the 20th character... it's OK for me to loose the
    middse initial

    My best guess is this for the code:

    FieldString = (emp.LastName & "," & emp.FirstName & "
    " & emp.MI)
    EmpList.Write(F ieldString.PadR ight(20, " "c))

    But I don't think this will work. Any ideas? thanks!!!




  • Jack Jackson

    #2
    Re: limiting number of characters - pad

    On Wed, 15 Oct 2008 12:56:56 -0700 (PDT), Brock <wade.brock@yah oo.com>
    wrote:
    >Thanks in advance... I have a string that I'm building that needs to
    >write to a file the last name, first name and middle initial in this
    >format with a maximum of 20 characters. Two examples:
    >
    >Brenda J Lanier
    >Lanier,Brend a J
    >
    ' note that this name is only 15 characters, with the space and
    >comma, after formatting so I'm safe
    >
    >Edward M Berksweller:
    >Berksweller,Ga rrett M
    >
    ' note that this name has 21 characters, with the space and comma,
    >so to stay within the 20 char limit it needs to write as:
    >Berksweller,Ga rrett
    >with the space being the 20th character... it's OK for me to loose the
    >middse initial
    >
    >My best guess is this for the code:
    >
    FieldString = (emp.LastName & "," & emp.FirstName & "
    >" & emp.MI)
    EmpList.Write(F ieldString.PadR ight(20, " "c))
    >
    >But I don't think this will work. Any ideas? thanks!!!
    Your explanation of what you want is confusing, and it didn't help
    that you used an example in which the middle initial just put you over
    the 20 character limit.

    If your requirement is to use the first 20 characters of
    "lastname,first name m" regardless of where the break occurs in the
    name (what if the last name is 20 chars, or if the 20 character
    limit is in the middle of the first name?), then:

    FieldString = (emp.LastName & "," & emp.FirstName & " " & emp.MI)
    EmpList.Write(F ieldString.PadR ight(20).SubStr ing(0, 20))

    Comment

    Working...