Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-04-08
5
Medium Priority
?
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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