Troubles when reading csv in vb.net (using LumenWorks) -


i need make vb.net program using lumenworks reads each line of .csv file. first line of file contains names of fields, , next lines contain information, , fields delimited coma (,).

most of lines okay, there few lines 1 of fields has comma in it, in cases quotes (") used, example of 4 fields (see "communication, management" 1 single field): united states, america,"communication, management",20/02/1997

this code @ moment. when csvreader gets line contains aforementioned quotes ("), error:

primera excepción del tipo 'lumenworks.framework.io.csv.missingfieldcsvexception' en lumenworks.framework.io.dll

i hope can me!

public sub readfile()         dim csv csvreader = new csvreader(new streamreader(path, system.text.encoding.default), true)          dim fieldcount integer = csv.fieldcount          dim headers string() = csv.getfieldheaders()         while csv.readnextrecord()             integer = 0 fieldcount - 1                 console.write(string.format("{0} = {1};", headers(i), csv(i)))                 console.writeline()             next                 end while      end sub 

use textfieldparser class built .net framework. part of .net framework. can see code samples in msdn foruns , on stack overflow csv issue

dim textfilereader new microsoft.visualbasic.fileio.textfieldparser("c:\path\to\file\semicolondelimited.txt")  textfilereader.textfieldtype = fileio.fieldtype.delimited textfilereader.setdelimiters(";")  ' ... 

you can use linq. please note lumenworks csv little picky:

is valid csv escaping? lumenworks throws exception other parsers seem work


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -