parse text field

Discussion in 'ASP General' started by Bennie Sanders, Apr 22, 2004.

  1. Hello,

    I have a text file with 142 lines, each line beginning with a job number
    and a line number, like this:

    "9426 1"
    "9426 2"

    through 9426142

    I've used the left function to extract the 9426 but how can I separate
    what's left over? The right function isn't returning the remaining
    value properly because there aren't always three characters to the right
    of 9426. I'm stumped. Any help would be appreciated. Thank you.


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Bennie Sanders, Apr 22, 2004
    #1
    1. Advertising

  2. Bennie Sanders

    Ray at Guest

    TheRightPart = Right(yourValue, Len(yourValue) - Len("9426"))

    Instead of Len("9426"), you could of course just put the number 4, but it's
    a little clearer using a value or a constant as opposed to what could appear
    as just an arbitrary number.

    Ray at home


    "Bennie Sanders" <> wrote in message
    news:%...
    >
    >
    > Hello,
    >
    > I have a text file with 142 lines, each line beginning with a job number
    > and a line number, like this:
    >
    > "9426 1"
    > "9426 2"
    >
    > through 9426142
    >
    > I've used the left function to extract the 9426 but how can I separate
    > what's left over? The right function isn't returning the remaining
    > value properly because there aren't always three characters to the right
    > of 9426. I'm stumped. Any help would be appreciated. Thank you.
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Ray at, Apr 22, 2004
    #2
    1. Advertising

  3. I used to do it that way, but I've since found it better to use the Mid()
    function. If you don't specify the 'end' variable, it will select
    everything remaining in the string. So if you want to select everything
    from the fifth character onwards, you would use:
    TheRightPart = Mid(yourValue, 5)

    IMHO, the Mid() function is best to select everything from a known
    character position onwards, and the Right() function is best to select a
    known number of characters.

    Blair

    Ray at <%=sLocation%> [MVP] <myfirstname at lane34 dot com> wrote in
    article <O5oq#>...
    > TheRightPart = Right(yourValue, Len(yourValue) - Len("9426"))
    >
    > Instead of Len("9426"), you could of course just put the number 4, but

    it's
    > a little clearer using a value or a constant as opposed to what could

    appear
    > as just an arbitrary number.
    >
    > Ray at home
    Blair Bonnett, Apr 22, 2004
    #3
  4. Bennie Sanders

    Roland Hall Guest

    "Bennie Sanders" wrote in message
    news:%...
    : I have a text file with 142 lines, each line beginning with a job number
    : and a line number, like this:
    :
    : "9426 1"
    : "9426 2"
    :
    : through 9426142

    What is after the job and line number on those lines and is there really 2
    spaces between job and line number?

    : I've used the left function to extract the 9426 but how can I separate
    : what's left over? The right function isn't returning the remaining
    : value properly because there aren't always three characters to the right
    : of 9426.

    There aren't always three characters or three numbers? You show two spaces
    in the first two lines.

    If there are always two spaces and more text on the line since you said
    "each line beginning with a job number and a line number" then:

    dim job, line, temp
    str = "9426 1 some other text"
    job = left(str,4)
    line = trim(mid(str,5,3))

    HTH...

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
    Roland Hall, Apr 22, 2004
    #4
  5. Ray,

    Your method worked perfectly. Here's what I came up with:

    PLANID=left(datcols(0),4)
    LINE_NO = Right(datcols(0), Len(datcols(0)) - Len(PLANID))

    LINE_NO is what I was trying to achieve and it works great. Many thanks
    for your help and also to the others.

    Bennie

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Bennie Sanders, Apr 22, 2004
    #5
  6. Bennie Sanders

    Ray at Guest

    I agree. This is a bit more pleasant to look at!

    Ray at work

    "Blair Bonnett" <> wrote in message
    news:01c4282e$859d4620$309460cb@default...
    > I used to do it that way, but I've since found it better to use the Mid()
    > function. If you don't specify the 'end' variable, it will select
    > everything remaining in the string. So if you want to select everything
    > from the fifth character onwards, you would use:
    > TheRightPart = Mid(yourValue, 5)
    >
    > IMHO, the Mid() function is best to select everything from a known
    > character position onwards, and the Right() function is best to select a
    > known number of characters.
    >
    > Blair
    >
    > Ray at <%=sLocation%> [MVP] <myfirstname at lane34 dot com> wrote in
    > article <O5oq#>...
    > > TheRightPart = Right(yourValue, Len(yourValue) - Len("9426"))
    > >
    > > Instead of Len("9426"), you could of course just put the number 4, but

    > it's
    > > a little clearer using a value or a constant as opposed to what could

    > appear
    > > as just an arbitrary number.
    > >
    > > Ray at home
    Ray at, Apr 22, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry Manner
    Replies:
    5
    Views:
    544
    Jonathan N. Little
    Jun 9, 2005
  2. ehm
    Replies:
    2
    Views:
    195
  3. Roy Adams

    writing from hidden field to text field

    Roy Adams, Dec 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    182
  4. Sound
    Replies:
    2
    Views:
    426
    Randy Webb
    Sep 28, 2006
  5. jr
    Replies:
    3
    Views:
    405
Loading...

Share This Page