parsing text file into DataTable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to parse an third party supplied delimited or fixed width text file
into a datatable. The delimiter may vary.

I am currently using a SteamReader to read each line and, for delimited
files, String.Split() to break each line into an array based on the
delimiter. The problem, as you may guess, is that the delimiter character is
being used in the data

i.e. "Kevin","Williams,"I like commas, I really do"

In the above I get an array with 4 elements and not 3 when the delimiter is
a comma.

My next stop is the Jet OLEDB provider, which expects CSV by default and
which I understand will handle other delimiters with a Schema.ini file.
Seems easy enough...

QUESTION:
Is there a better way than Jet or some .Net class that I am overlooking?
 
Hello Kevin,

Is there any way to use specific symbol as delimiter, not comma?
Problem not in classes but in sentence analysis of you data. You need smth
better to keep info rather than plain text

K> I need to parse an third party supplied delimited or fixed width text
K> file into a datatable. The delimiter may vary.
K>
K> I am currently using a SteamReader to read each line and, for
K> delimited files, String.Split() to break each line into an array
K> based on the delimiter. The problem, as you may guess, is that the
K> delimiter character is being used in the data
K>
K> i.e. "Kevin","Williams,"I like commas, I really do"
K>
K> In the above I get an array with 4 elements and not 3 when the
K> delimiter is a comma.
K>
K> My next stop is the Jet OLEDB provider, which expects CSV by default
K> and which I understand will handle other delimiters with a Schema.ini
K> file. Seems easy enough...
K>
K> QUESTION:
K> Is there a better way than Jet or some .Net class that I am
K> overlooking?
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Hi Kevin,

Take a look at opennetcf.org they provide a CSV parser, has you will have
the code you can change (dont remember if this feature is present or not)
the code to instead of "," use any other character you want.

This should be fairly trivial
 
This should be fairly trivial

Thats a bit of an overstatement, isn't it. I found a project on
CodeProject.com and that project is anything but trivial... not overwhelming,
but involved.

http://www.thecodeproject.com/cs/database/CsvReader.asp?df=100&forumid=142714&exp=0&select=1499295

I actually decided to go with the regex solution. I'll first use split and
if that returns and array with an incorrect size (I will know the number of
fields), then I'll use the regex expression.

Thanks for the input
 
Hi,


I meant using or adapting the code from opennetcf.org , I know it's not
trivial :)

I believe your selected path is not the best approach, just use one of the
already in existence solutions.


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
 
Back
Top