View previous topic :: View next topic |
Author |
Message |
tim
Joined: 02 Nov 2004 Posts: 5
|
Posted: Thu Nov 11, 2004 4:45 pm Post subject: Getting data from comma-delimited file... |
|
|
I have a text file with comma-delimited data in it. I read the file in ASP with FileSystemObject and I want to extract the data in the second field (the one after the first comma).
Example:
Item1, Customer1, Price1, Date1
Item2, Customer2, Price2, Date2
Item3, Customer1, Price3, Date3
How can I do that? |
|
Back to top |
|
|
paul
Joined: 11 Oct 2004 Posts: 128
|
Posted: Fri Nov 12, 2004 9:40 am Post subject: |
|
|
Hi Tim,
You can use the Split VBScript function to get and array of values for each line in your text file. The VBScript Split function separates a string into substrings and puts those substrings into one-dimensional array where each substring is an element.
The VBScript Split function takes 2 parameters, the first one is the string you want to split, the second one is your delimiter string (comma in your case). You can omit the delimiter parameter when calling the Split function and in this case the delimiter will be the default one - single empty space.
Remember that the result of Split VBScript function execution is zero-based array, so the second item on your line will be arrTextFileLine(1)
In your case you need to do the following:
Code: |
<%
sLine = "Item1,Customer1,Price1,Date1 "
arrTextFileLine = Split(sLine, ",")
Response.Write arrTextFileLine(1) ' This will print the second element on your line.
%>
|
I hope this helps,
Paul _________________ World Countries | Survival Skills |
|
Back to top |
|
|
tim
Joined: 02 Nov 2004 Posts: 5
|
Posted: Fri Nov 12, 2004 9:52 am Post subject: |
|
|
Thanks Paul,
You almost wrote a full VBScript Split article here .
It's highly appreciate it!
Tim |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group
|