[thelist] ASP Question - Parsing a string

Chris Blessing webguy at mail.rit.edu
Wed Mar 27 12:40:01 CST 2002


Jim-

I don't believe there's a built-in function, but you could use this:

<%
dim j, stringArray
stringArray = strToArray("This is the string.")

' show the array that was generated
for j=0 to ubound(stringArray)-1
	Response.Write j & ". " & stringArray(j) & "<BR>"
next

function strToArray(str)
	' make sure we have a string of some length
	if len(str) > 0 then
		dim i, theArray()

		' setup the array to hold all the characters
		redim theArray(len(str))

		' add each character to the array at its
		' proper location
		for i=0 to len(str)
			theArray(i) = mid(str, i+1, 1)
		next

		' return the array
		strToArray = theArray
	end if
end function
%>

This way you only redim once (which is preferrable over multiple times for
performance reasons).

Chris Blessing
webguy at mail.rit.edu
http://www.330i.net


> Hi all,
>
> I'm new to ASP and could use some help.  I need to take a
> varibale (string)
> that contains 7 characters (for example: abcde01) and put it into an array
> (for example:  array index: 0  array content: a, array index: 1 array
> content: b etc.)  Does VBscript have a built in function that will
> accomplish or must I write my own function.
>
> TIA
>
> Jim Williamson
> Interactive Training Developer




More information about the thelist mailing list