Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post

    Insert text from variable into an array

    How can I possibly divide up text into an array or similar?

    Like..
    Code:
    Line1
    Line2
    Line3
    Line4
    Line5
    Into an array?

    The text is in a variable already but I need to split it up into an array like I said.

    I'm getting this text from a python proggy, I can present the text in any way I like so if you think it would be better to have some character signifying the start and end of the line I can do that.
    Omnis mico antequam dominus Spookster!

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Doh! split()...

    I'm having such a bad day, I'd forget my head if it weren't screwed on. (not literally of course!)
    Omnis mico antequam dominus Spookster!

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hehe, I use split all the time... usually what I do is concatenate a string like:

    If so and so
    stringname = stringname & variable & "|"
    End If

    usually in a loop instead, so you end up with stuff like:

    asdf|asdf|asdf|asdf|asdf|

    Then I just trim off the last pipe:

    If Len(stringname) > 0 Then
    stringname = Left(stringname,Len(stringname-1))
    stringarray = Split(stringname,"|")
    End If

    Dim iCount
    For iCount = 0 to UBound(stringarray)
    ' Do Something
    Next

    Of course if you already have your string delimited by something then you can just split it up by that character or combination of characters.

    For instance, check out this function, it will change a comma-delimited string with a double-quote text identifier into a pipe-delimited string:

    <%
    mystring = """rob"",""blah"""
    Response.Write(Comma2Pipe(mystring))
    Function Comma2Pipe(byVal str)
    If IsNull(str) Then Exit Function
    Comma2Pipe = Replace(Replace(str,""",""","|"),chr(34),"")
    End Function
    %>


    Last edited by whammy; 02-13-2003 at 02:37 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

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