Connecting Tech Pros Worldwide Forums | Help | Site Map

parsing text file into DataTable

kevin
Guest
 
Posts: n/a
#1: Jun 14 '06
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?

--
kevin...

Balasubramanian Ramanathan
Guest
 
Posts: n/a
#2: Jun 14 '06

re: parsing text file into DataTable


You can use regex..its more powerful.
"kevin" <kevin@discussions.microsoft.com> wrote in message
news:25E18B60-E631-4AF9-8FD9-383CDAD2F76F@microsoft.com...[color=blue]
>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?
>
> --
> kevin...[/color]


Michael Nemtsev
Guest
 
Posts: n/a
#3: Jun 14 '06

re: parsing text file into DataTable


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


Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
#4: Jun 14 '06

re: parsing text file into DataTable


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


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

"kevin" <kevin@discussions.microsoft.com> wrote in message
news:25E18B60-E631-4AF9-8FD9-383CDAD2F76F@microsoft.com...[color=blue]
>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?
>
> --
> kevin...[/color]


kevin
Guest
 
Posts: n/a
#5: Jun 15 '06

re: parsing text file into DataTable


>>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/dat...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


--
kevin...


"Ignacio Machin ( .NET/ C# MVP )" wrote:
[color=blue]
> 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
>
>
> --
> --
> Ignacio Machin,
> ignacio.machin AT dot.state.fl.us
> Florida Department Of Transportation
>
> "kevin" <kevin@discussions.microsoft.com> wrote in message
> news:25E18B60-E631-4AF9-8FD9-383CDAD2F76F@microsoft.com...[color=green]
> >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?
> >
> > --
> > kevin...[/color]
>
>
>[/color]
Marcos
Guest
 
Posts: n/a
#6: Jun 17 '06

re: parsing text file into DataTable


You can try also with the FileHelpers

http://filehelpers.sourceforge.net/

Best Regards

kevin ha escrito:
[color=blue][color=green][color=darkred]
> >>This should be fairly trivial[/color][/color]
>
> 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/dat...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
>
>
> --
> kevin...
>
>
> "Ignacio Machin ( .NET/ C# MVP )" wrote:
>[color=green]
> > 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
> >
> >
> > --
> > --
> > Ignacio Machin,
> > ignacio.machin AT dot.state.fl.us
> > Florida Department Of Transportation
> >
> > "kevin" <kevin@discussions.microsoft.com> wrote in message
> > news:25E18B60-E631-4AF9-8FD9-383CDAD2F76F@microsoft.com...[color=darkred]
> > >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?
> > >
> > > --
> > > kevin...[/color]
> >
> >
> >[/color][/color]

Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
#7: Jun 19 '06

re: parsing text file into DataTable


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




"kevin" <kevin@discussions.microsoft.com> wrote in message
news:BB11591C-830E-4BBB-AB0C-F76F27D15E61@microsoft.com...[color=blue][color=green][color=darkred]
>>>This should be fairly trivial[/color][/color]
>
> 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/dat...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
>
>
> --
> kevin...
>
>
> "Ignacio Machin ( .NET/ C# MVP )" wrote:
>[color=green]
>> 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
>>
>>
>> --
>> --
>> Ignacio Machin,
>> ignacio.machin AT dot.state.fl.us
>> Florida Department Of Transportation
>>
>> "kevin" <kevin@discussions.microsoft.com> wrote in message
>> news:25E18B60-E631-4AF9-8FD9-383CDAD2F76F@microsoft.com...[color=darkred]
>> >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?
>> >
>> > --
>> > kevin...[/color]
>>
>>
>>[/color][/color]


Closed Thread