breaking a string into components

Discussion in 'ASP General' started by Thomas Brooks, Jan 20, 2004.

  1. Hi everybody....

    Here's a question for you. I think the answer is simple, but I'm not sure
    how to go about it...what I want to do is to break down a string into
    components. I already know about the LEFT, MID, and RIGHT properties, but I
    don't believe they'll work in this case. Anyway:

    I have an ASP page where I retrieve data off of a database
    recordset...something like:

    variable1=RecSet1(0)

    the data stored in RecSet1(0) is something like AA,BB,CC,DD,EE or there may
    even be spaces like AA, BB, CC, DD, EE

    what I would like to do is to set up some new variables as pieces of the
    string....so,

    newvariable1 = whatever is to the left of the first comma
    newvariable2 = whatever is between the first and second comma

    etc...

    I can trim out spaces later....I just need to know how to gather pieces in
    front of, in between, or after a delimiter like a comma

    Thanks

    Tom
     
    Thomas Brooks, Jan 20, 2004
    #1
    1. Advertising

  2. Thomas Brooks

    Steven Burn Guest

    Look at the Split function.

    e.g. strThingymibob = Split(strData, ",") 'Split via comma

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    Disclaimer:
    I know I'm probably wrong, I just like taking part ;o)


    Thomas Brooks <> wrote in message
    news:5LaPb.2964$...
    > Hi everybody....
    >
    > Here's a question for you. I think the answer is simple, but I'm not sure
    > how to go about it...what I want to do is to break down a string into
    > components. I already know about the LEFT, MID, and RIGHT properties, but

    I
    > don't believe they'll work in this case. Anyway:
    >
    > I have an ASP page where I retrieve data off of a database
    > recordset...something like:
    >
    > variable1=RecSet1(0)
    >
    > the data stored in RecSet1(0) is something like AA,BB,CC,DD,EE or there

    may
    > even be spaces like AA, BB, CC, DD, EE
    >
    > what I would like to do is to set up some new variables as pieces of the
    > string....so,
    >
    > newvariable1 = whatever is to the left of the first comma
    > newvariable2 = whatever is between the first and second comma
    >
    > etc...
    >
    > I can trim out spaces later....I just need to know how to gather pieces in
    > front of, in between, or after a delimiter like a comma
    >
    > Thanks
    >
    > Tom
    >
    >
     
    Steven Burn, Jan 20, 2004
    #2
    1. Advertising

  3. Thomas Brooks

    Ray at Guest

    How about using an array and splitting, like so:

    <%
    sString = "AA, BB, CC, DD, EE"
    sString = Replace(sString, " ", "") ''optional. Might want to replacey ", "
    with "," or do nothing at all
    aParts = Split(sString, ",")

    For i = 0 To UBound(aParts)
    Response.Write "Part " & CStr(i + 1) & " is " & aParts(i) & "<br>"
    Next
    %>

    Ray at work


    "Thomas Brooks" <> wrote in message
    news:5LaPb.2964$...
    > Hi everybody....
    >
    > Here's a question for you. I think the answer is simple, but I'm not sure
    > how to go about it...what I want to do is to break down a string into
    > components. I already know about the LEFT, MID, and RIGHT properties, but

    I
    > don't believe they'll work in this case. Anyway:
    >
    > I have an ASP page where I retrieve data off of a database
    > recordset...something like:
    >
    > variable1=RecSet1(0)
    >
    > the data stored in RecSet1(0) is something like AA,BB,CC,DD,EE or there

    may
    > even be spaces like AA, BB, CC, DD, EE
    >
    > what I would like to do is to set up some new variables as pieces of the
    > string....so,
    >
    > newvariable1 = whatever is to the left of the first comma
    > newvariable2 = whatever is between the first and second comma
    >
    > etc...
    >
    > I can trim out spaces later....I just need to know how to gather pieces in
    > front of, in between, or after a delimiter like a comma
    >
    > Thanks
    >
    > Tom
    >
    >
     
    Ray at, Jan 20, 2004
    #3
    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. Bob Robertson
    Replies:
    2
    Views:
    387
    Kevin Spencer
    Aug 11, 2005
  2. hank barta
    Replies:
    4
    Views:
    414
    Wendy S
    Jan 21, 2004
  3. Mickey Segal
    Replies:
    0
    Views:
    938
    Mickey Segal
    Feb 2, 2004
  4. Jacques Vidal
    Replies:
    1
    Views:
    379
    Bryce
    Jul 21, 2004
  5. Amy
    Replies:
    0
    Views:
    538
Loading...

Share This Page