Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Allow space in this pattern 2 46
Error on Add method 1 37
Change Format on Data when exporting to Excel 4 23
Angular - break the dataset in chunks? 7 38
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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

930 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

13 Experts available now in Live!

Get 1:1 Help Now