PDA

View Full Version : parsing a string for values


havey
10-13-2006, 01:58 AM
Hi i'm confused on this one, guess it don't take much these days...


I have a string like so (between the quotes):

"./ ../ .bash_history 100015_200610111421_4001721_S.XML 100015_200610111442_4001721_M.XML 100015_200610111442_4001721_C.XML "

this is alway at the begining: "./ ../ .bash_history " and the xml files always have 3 underscores in them and are always: something_something_something_oneCharacter(either a C,M,or S).xml

Some times the string will have 1 xml file name and sometimes may upwards of 10 xml file names. My goal is to parse the string and set each to a variable.

this is how i think it should be started, but like i mentioned, it don't take much these days to confuse me:

myArray = Split("./ ../ .bash file.xml file_name_here.xml pagefile_here.xml"," ")

so from here how would i set each xml file name (including the .xml) to a variable? Thanks!

Spudhead
10-13-2006, 09:36 AM
I guess I'd take the bash bit off the front before splitting it, but after you've split it you'll just have a filename in each array element. ie:

for i=0 to uBound(myArray)
myFileName = myArray(i)
response.write(myFileName & "<br/>")
next

Is that what you mean?

degsy
10-13-2006, 03:31 PM
You want the filename to be a variable? If so you would have to use Execute()


<%
str = "./ ../ .bash_history 100015_200610111421_4001721_S.XML 100015_200610111442_4001721_M.XML 100015_200610111442_4001721_C.XML "
str = Trim(Replace(str,"./ ../ .bash_history",""))
arr = Split(str," ")

For x=0 To Ubound(arr)
If arr(x) <> "" Then
Execute("var" & x & "=""" & arr(x) & """")
End If
Next

For x=0 To UBound(arr)
Response.Write "var" & x & " = " & Eval("var" & x) & "<br>"
Next
%>


otherwise the names are already stored in the array