SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Location
    NC USA
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Split Array from Querystring

    Hello All;

    OK, this is the scenario.
    Querystring: grab=1+2+3+4

    OK, I need it to end up like this
    1 and 2 and 3 and 4

    As you can see, there is no "and" at the end.

    I have tried this, however, it does not work.
    As it outputs as:
    1 and 2 and 3 and 4 and
    Code:
    <%
    mystring = split("1 2 3 4"," ")
    for n=0 to ubound (mystring)
    str = mystring(n) & " and "
    response.Write str
    next
    %>
    I have tried to do a
    left(str, len(str)-1)
    But that will remove every instance of the "and".

    Any idea's on this would be great.
    Thanks You
    Carrzkiss

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <%

    Q = "1 2 3 4"

    Q = replace (Q, " ", " and ")

    response.write Q

    %>

  3. #3
    SitePoint Member
    Join Date
    Jun 2013
    Location
    NC USA
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello webber
    Thanks for the reply, however, I need it done in an Array.
    As each part of the results, will be utilized in the project.
    Just doing the replace, and then presenting that result, will not work.

    Thanks for the reply thought, much appreciated
    Carrzkiss

  4. #4
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <%

    mystring = split("1 2 3 4"," ")
    z=ubound (mystring)
    for n=0 to ubound (mystring) - 1
    str = str & mystring(n) & " and "
    next
    str = str & mystring(z)
    response.Write str

    %>

  5. #5
    SitePoint Member
    Join Date
    Jun 2013
    Location
    NC USA
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is it!!!
    Thank you so much Webber.
    I was so close, but yet, so far away in my code.

    How do you accept an answer on here?
    Carrzkiss

  6. #6
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by carrzkiss View Post
    That is it!!!
    Thank you so much Webber.
    I was so close, but yet, so far away in my code.

    How do you accept an answer on here?
    Carrzkiss
    You cant :'(

  7. #7
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Ref. the Split Array Thread

    Edit:

    post merged


    There is a much easier and better way to achieve the required result.

    Code ASP:
    <%
    myArr = Split ("1 2 3 4", " ")
    str = Join (myArr, " and ")
    Response.write str
    %>

    Or even ...

    Code ASP:
    <%
    myStr = "1 2 3 4"
    str = Replace (myStr, " ", " and ")
    Response.write str
    %>
    Last edited by Mittineague; Jun 13, 2013 at 07:39.
    Ian Anderson
    www.siteguru.co.uk


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •