Solved

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

Posted on 2009-04-08
5
308 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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 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