SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    "Splitting" an already split string

    Here's the deal. I'm trying to work with sort of a home-grown flat-file database. The structure looks something like this:

    Code:
    A1,A2,A3 ||
    B1,B2,B3||
    In JavaScript, I can parse this easily using the String.split method. For example,

    Code:
    var c620_patchnum = data.split("||")[0].split(",")[2];
    Would access "A3". However, in ASP, I'm having trouble splitting the string a "second" time; as in, accessing an element in that split array and then running String.split again.


    And so I'm just wondering what the equiv. syntax in ASP Classic/VBScript would be. Thank you, all.

    Regards,
    Fred

  2. #2
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind, figured it out:

    Code:
    <%
    	str = "part1, part2 || part3, part4, part5"
    	
    
    	split_vers = Split(str, "||")
    	
    	Response.Write( Split(split_vers(1), ",")(0) ) // prints "part3"
    %>
    Just took a little more tinkering...

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Location
    OH, USA
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can y=use something like


    Code:
    <% 
    'on error resume next
    str = "A1,A2,A3 ||B1,B2,B3||"
    
    	rows = Split(str, "||")
    	Set a = CreateObject("Scripting.Dictionary")
    	for i=0 to ubound(rows) 
             a.Add i, Split(rows(i), ",") 
    	next
    	
    	Response.Write a.Item(0)(1)
    %>

  4. #4
    SitePoint Member Kul-Tigin's Avatar
    Join Date
    Aug 2011
    Location
    Turkey
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try the following:
    Code ASP:
    data = "A1,A2,A3 ||"
    Response.Write Split(Split(data,"||")(0), ",")(2)

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    gk53's method is good if you need to reference multiple items.
    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
  •