469,950 Members | 2,061 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

String split and wrapper character in c#

Hi all,

I have a csv file exported from excel. On cells where there was a comma
in the text, it wraps the character with double quotes. For example:

Column 1,"column two, and some more stuff",Column 3

In a c# dll, .NET framework 1.1, I'm reading the file using a
streamreader then retrieving each line into a string using
reader.ReadLine().

If I use the normal string.Split(',') it ends up splitting the line
into 4 strings:
Column 1
"column two
and some more stuff"
Column 3

Whereas I need it to be split into this:
Column 1
"column two, and some more stuff"
Column 3

Is there a proven and efficient method of splitting the line but
keeping the wrapper character in mind?

Cheers,
Thiago

Aug 16 '06 #1
4 3857
Thiago,

I would actually use the classes in the System.Data.OleDb namespace for
this. Check out the following thread on MSDN forums, it should give you a
good start:

http://forums.microsoft.com/MSDN/Sho...=6015&SiteID=1

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<th**********@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hi all,

I have a csv file exported from excel. On cells where there was a comma
in the text, it wraps the character with double quotes. For example:

Column 1,"column two, and some more stuff",Column 3

In a c# dll, .NET framework 1.1, I'm reading the file using a
streamreader then retrieving each line into a string using
reader.ReadLine().

If I use the normal string.Split(',') it ends up splitting the line
into 4 strings:
Column 1
"column two
and some more stuff"
Column 3

Whereas I need it to be split into this:
Column 1
"column two, and some more stuff"
Column 3

Is there a proven and efficient method of splitting the line but
keeping the wrapper character in mind?

Cheers,
Thiago

Aug 16 '06 #2

Hmm, I had a look at that forum, pretty interesting stuff. It looks
like using the Microsoft Jet OleDb adapter would be a good way to go
about it. My only concern is: my DLL will be receiving the csv data in
a stream in the future instead of picking it up from a file... Does
this mean I'd have to save the stream to a file then use the OleDb
adapter to load it?

Thanks,
Thiago

Nicholas Paldino [.NET/C# MVP] wrote:
Thiago,

I would actually use the classes in the System.Data.OleDb namespace for
this. Check out the following thread on MSDN forums, it should give you a
good start:

http://forums.microsoft.com/MSDN/Sho...=6015&SiteID=1

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<th**********@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hi all,

I have a csv file exported from excel. On cells where there was a comma
in the text, it wraps the character with double quotes. For example:

Column 1,"column two, and some more stuff",Column 3

In a c# dll, .NET framework 1.1, I'm reading the file using a
streamreader then retrieving each line into a string using
reader.ReadLine().

If I use the normal string.Split(',') it ends up splitting the line
into 4 strings:
Column 1
"column two
and some more stuff"
Column 3

Whereas I need it to be split into this:
Column 1
"column two, and some more stuff"
Column 3

Is there a proven and efficient method of splitting the line but
keeping the wrapper character in mind?

Cheers,
Thiago
Aug 16 '06 #3
Yes, it's a limitation of both the jet driver and the odbc driver that
the data must be in an action file.

Optionally, you can check out the commercial product that I sell,
http://www.csvreader.com .

Bruce Dunwiddie

th**********@yahoo.com wrote:
Hmm, I had a look at that forum, pretty interesting stuff. It looks
like using the Microsoft Jet OleDb adapter would be a good way to go
about it. My only concern is: my DLL will be receiving the csv data in
a stream in the future instead of picking it up from a file... Does
this mean I'd have to save the stream to a file then use the OleDb
adapter to load it?

Thanks,
Thiago

Nicholas Paldino [.NET/C# MVP] wrote:
Thiago,

I would actually use the classes in the System.Data.OleDb namespace for
this. Check out the following thread on MSDN forums, it should give you a
good start:

http://forums.microsoft.com/MSDN/Sho...=6015&SiteID=1

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<th**********@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hi all,
>
I have a csv file exported from excel. On cells where there was a comma
in the text, it wraps the character with double quotes. For example:
>
Column 1,"column two, and some more stuff",Column 3
>
In a c# dll, .NET framework 1.1, I'm reading the file using a
streamreader then retrieving each line into a string using
reader.ReadLine().
>
If I use the normal string.Split(',') it ends up splitting the line
into 4 strings:
Column 1
"column two
and some more stuff"
Column 3
>
Whereas I need it to be split into this:
Column 1
"column two, and some more stuff"
Column 3
>
Is there a proven and efficient method of splitting the line but
keeping the wrapper character in mind?
>
Cheers,
Thiago
>
Aug 16 '06 #4
This here seems to do the trick:
http://www.codeproject.com/cs/database/CsvReader.asp

Thank you for the replies.

Thiago

shriop wrote:
Yes, it's a limitation of both the jet driver and the odbc driver that
the data must be in an action file.

Optionally, you can check out the commercial product that I sell,
http://www.csvreader.com .

Bruce Dunwiddie

th**********@yahoo.com wrote:
Hmm, I had a look at that forum, pretty interesting stuff. It looks
like using the Microsoft Jet OleDb adapter would be a good way to go
about it. My only concern is: my DLL will be receiving the csv data in
a stream in the future instead of picking it up from a file... Does
this mean I'd have to save the stream to a file then use the OleDb
adapter to load it?

Thanks,
Thiago

Nicholas Paldino [.NET/C# MVP] wrote:
Thiago,
>
I would actually use the classes in the System.Data.OleDb namespace for
this. Check out the following thread on MSDN forums, it should give you a
good start:
>
http://forums.microsoft.com/MSDN/Sho...=6015&SiteID=1
>
Hope this helps.
>
>
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
>
>
<th**********@yahoo.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
Hi all,

I have a csv file exported from excel. On cells where there was a comma
in the text, it wraps the character with double quotes. For example:

Column 1,"column two, and some more stuff",Column 3

In a c# dll, .NET framework 1.1, I'm reading the file using a
streamreader then retrieving each line into a string using
reader.ReadLine().

If I use the normal string.Split(',') it ends up splitting the line
into 4 strings:
Column 1
"column two
and some more stuff"
Column 3

Whereas I need it to be split into this:
Column 1
"column two, and some more stuff"
Column 3

Is there a proven and efficient method of splitting the line but
keeping the wrapper character in mind?

Cheers,
Thiago
Aug 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Stu Cazzo | last post: by
4 posts views Thread by Simon Schaap | last post: by
7 posts views Thread by Mad Scientist Jr | last post: by
5 posts views Thread by kurt sune | last post: by
4 posts views Thread by WaterWalk | last post: by
10 posts views Thread by vunet.us | last post: by
7 posts views Thread by Johny | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.