473,396 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 4007
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
7
by: Mad Scientist Jr | last post by:
I have been doing this kind of thing in VB and VB.net for a long time, but am having problems in C#: First I want to split up a string by the backslash character, but this line: arrSplit =...
23
by: Rogers | last post by:
I want to compare strings of numbers that have a circular boundary condition. This means that the string is arranged in a loop without an end-of-string. The comparaison of two strings now...
16
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array...
5
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() =...
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
10
by: vunet.us | last post by:
Hello, I use XMLHTTP to get an HTML of another page. Then, I need to cut some middle part of that HTML string but I have problems doing it (see note in caps below). The error I have generated at...
7
by: Johny | last post by:
I have a string of a variable length and I need to split the string in strings of 6 characters . But if the 6th character is not space then I must split the string at possition before the 6th...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.