Read in different width CSV files
Hi All,
I hope someone can help me I have a CSV file that comes from a DOS application (3rd party) and it output data as a CSV files so that is Fine but my problem is the file holds differnt lengths of rows For example
ADD,5018374320766,VALUE ORANGE JUICE, 0001,,035
DELETE,50201600
DEPT_ADD,0002,GROCERY,O,A
So how do i read this in so I can process the files (ideal I would like to use native code that i can covert backward for VB6)
Any infor or sample code would be most welcomed as I have been looking at this now for a month and I can read the first line in with no problem but the second and third line loads into the fields
Re: Read in different width CSV files
Assuming you know what to do with each 'bit' of the incoming data, you could 'split' each line on the comma as you read it in e.g. you read in 'ADD,5018374320766,VALUE ORANGE JUICE, 0001,,035' ,"," and put into a string variable called 'Line'
Code:
dim bits() as string = split(Line ,",")
This will put 'ADD' in bits(0), 5018374320766 in bits(1) and so on....and DELETE in bits(0) 50201600 in bits(1) on the next read.
Re: Read in different width CSV files
Do you need to change the data or just read it. lots of ways to handle your request, probably oledb would be an idea solution to get the data into a datatable
Re: Read in different width CSV files
I thought the TextFieldParser ReadLine method would handle lines with various column counts. Have you tried it?
Re: Read in different width CSV files
Quote:
Originally Posted by
bmwpete
Assuming you know what to do with each 'bit' of the incoming data, you could 'split' each line on the comma as you read it in e.g. you read in 'ADD,5018374320766,VALUE ORANGE JUICE, 0001,,035' ,"," and put into a string variable called 'Line'
Code:
dim bits() as string = split(Line ,",")
This will put 'ADD' in bits(0), 5018374320766 in bits(1) and so on....and DELETE in bits(0) 50201600 in bits(1) on the next read.
I never thought about that and then I could then do the what ever function I need to do from the Bits(0) (eg add a item or delete etc etc)