ASP Hosting sale!
Double disk space and transfer for FREE!
Limited time offer! Act Now!

aspdev | articles | tutorials | forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Getting data from comma-delimited file...

 
Post new topic   Reply to topic    ASPdev.org Forum Index -> ASP programming
View previous topic :: View next topic  
Author Message
tim



Joined: 02 Nov 2004
Posts: 5

PostPosted: Thu Nov 11, 2004 4:45 pm    Post subject: Getting data from comma-delimited file... Reply with quote

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
View user's profile Send private message
paul



Joined: 11 Oct 2004
Posts: 128

PostPosted: Fri Nov 12, 2004 9:40 am    Post subject: Reply with quote

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
View user's profile Send private message
tim



Joined: 02 Nov 2004
Posts: 5

PostPosted: Fri Nov 12, 2004 9:52 am    Post subject: Reply with quote

Thanks Paul,

You almost wrote a full VBScript Split article here Smile.

It's highly appreciate it!



Tim
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ASPdev.org Forum Index -> ASP programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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

SQL Tutorial