Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through a comma-delimited file to retrieve data. 2

Status
Not open for further replies.

Xopas

Programmer
Sep 16, 1999
8
US
I am having difficulty retrieving data from a comma delimited file (.csv) I am not as familiar with VBScript as I am with other languages. Could someone please let me know how I can loop through individual items in a comma-delimited string?<br>
<br>
Thank you.
 
Use the Split function, return an array and loop thru the array. Example below.<br>
<br>
I imagine you are using ASP since you are reading a disk-bound CSV file... however, since you didn't say so, I wrote this with all client side VBScript. If necessary, you can easily adapt it to server-side. Have fun.<br>
<br>
&lt;html&gt;<br>
&lt;head&gt;<br>
&lt;title&gt;&lt;/title&gt;<br>
<br>
&lt;script language="VBScript"&gt;<br>
Function ParseString(strToParse, delimiter)<br>
Dim aryString<br>
aryString = Split(strToParse, delimiter)<br>
ParseString = aryString<br>
End Function<br>
&lt;/script&gt;<br>
<br>
&lt;/head&gt;<br>
&lt;body&gt;<br>
<br>
&lt;script language="VBScript"&gt;<br>
Dim strMyCSV<br>
strMyCSV = "this,is,cool"<br>
<br>
Dim aryParsedString<br>
aryParsedString = ParseString(strMyCSV,",")<br>
<br>
Dim i<br>
For i = 0 to Ubound(aryParsedString)<br>
Document.Write aryParsedString(i) & "&lt;br&gt;"<br>
Next<br>
&lt;/script&gt;<br>
<br>
<br>
<br>
&lt;/body&gt;<br>
&lt;/html&gt;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top