Solved

How do I recognize a particular type of quotation mark set in C#?

Posted on 2009-04-08
5
302 Views
Last Modified: 2013-12-17
This question is a result from the question asked here:
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_24295748.html

It seems that quotation marks are not all the same.  How would I parse through different sets of quotation marks?  I use a StreamReader to read a file "C:\sample.csv" into a string "buffer" (line by line), then split this string by commas.

How can I detect the particular set of commas that are open (\\), straight (||), and closed (//)?
using (StreamReader reader = new StreamReader("C:\\sample.csv")) {

                string buffer;
 

                // Iterate through all lines

                while ((buffer = reader.ReadLine()) != null) {

                    string[] lineValues = buffer.Split(',');
 

                                    // Find the value with the first set of quotation marks

/**** EXPERTS-EXCHANGE - this is not picking up my expected set of question marks! ****/.

                                    while (!lineValues[i].Contains("\"")) 

                                        i++;
 

...

Open in new window

0
Comment
Question by:hyliandanny
  • 3
5 Comments
 
LVL 6

Expert Comment

by:HarryNS
ID: 24104024
string delimeter = ",";
StreamReader reader = new StreamReader(file);
//read the first line in and split it into columns
string[] columns = reader.ReadLine().Split(delimeter.ToCharArray());
0
 

Author Comment

by:hyliandanny
ID: 24104258
Even using the delimiter, as HarryNS suggested, results in the data being read as:

"ýJohnson"
" Joeý "

where the ý is actually a pair of quotation marks...
0
 

Author Comment

by:hyliandanny
ID: 24104262
Althought it is "ý" in the comments, that copy/paste is actually a square when viewed in the debugger.
0
 

Accepted Solution

by:
hyliandanny earned 0 total points
ID: 24104295
I found the problem.  Perhaps it will help you all avoid any similar mistakes in the future.

The sample format was given to me in a Microsoft Word document.  Consequently, when creating the CSV data sample I would test with, I copied and pasted the quotation mark characters within the sample from Microsoft Word into notepad.

This embellished, MS-Word-specific character is NOT equivalent to the quotation marks in the code.  That is why it was never picking it up.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now