• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

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

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
hyliandanny
Asked:
hyliandanny
  • 3
1 Solution
 
HarryNSCommented:
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
 
hyliandannyAuthor Commented:
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
 
hyliandannyAuthor Commented:
Althought it is "ý" in the comments, that copy/paste is actually a square when viewed in the debugger.
0
 
hyliandannyAuthor Commented:
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

Technology Partners: 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!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now