Results 1 to 5 of 5

Thread: Read in different width CSV files

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2014
    Location
    Northampton, UK
    Posts
    59

    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

  2. #2
    Addicted Member
    Join Date
    Jul 2017
    Location
    Exeter, UK
    Posts
    186

    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.

  3. #3
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    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

  4. #4
    Frenzied Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    1,145

    Re: Read in different width CSV files

    I thought the TextFieldParser ReadLine method would handle lines with various column counts. Have you tried it?

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2014
    Location
    Northampton, UK
    Posts
    59

    Re: Read in different width CSV files

    Quote Originally Posted by bmwpete View Post
    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
  •  



Click Here to Expand Forum to Full Width