|
-
Feb 22nd, 2019, 03:05 PM
#1
Thread Starter
Member
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
-
Feb 22nd, 2019, 04:07 PM
#2
Addicted Member
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.
-
Feb 22nd, 2019, 04:25 PM
#3
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
-
Feb 22nd, 2019, 07:28 PM
#4
Frenzied Member
Re: Read in different width CSV files
I thought the TextFieldParser ReadLine method would handle lines with various column counts. Have you tried it?
-
Feb 23rd, 2019, 11:33 AM
#5
Thread Starter
Member
Re: Read in different width CSV files
 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)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|