...

View Full Version : Insert text from variable into an array



Mhtml
02-11-2003, 07:11 AM
How can I possibly divide up text into an array or similar?

Like..


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.

Mhtml
02-11-2003, 09:26 AM
Doh! split()...

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

whammy
02-13-2003, 01:27 AM
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
%>


:D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum