C++ CSV line with commas and strings within double quotes

Using std::quoted allows you to read quoted strings from input streams. #include <iomanip> #include <iostream> #include <sstream> #include <string> int main() { std::stringstream ss; ss << “\”Primary, Secondary, Third\”, \”Primary\”, , \”Secondary\”, 18, 4, 0, 0, 0″; while (ss >> std::ws) { std::string csvElement; if (ss.peek() == ‘”‘) { ss >> std::quoted(csvElement); std::string discard; std::getline(ss, … Read more

mysql double-quoted table names

Taken from this post: SET GLOBAL SQL_MODE=ANSI_QUOTES; Personally when I tested, I had to do it like this: SET SQL_MODE=ANSI_QUOTES; I don’t think there’s any other way. http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_ansi_quotes ANSI_QUOTES Treat “”” as an identifier quote character (like the “`” quote character) and not as a string quote character. You can still use “`” to quote … Read more

json parse error with double quotes

Javascript unescapes its strings and json unescapes them as well. the first string ( ‘{“result”: [“lunch”, “\”Show\””] }’ ) is seen by the json parser as {“result”: [“lunch”, “”Show””] }, because \” in javascript means “, but doesn’t exit the double quoted string. The second string ‘{“result”: [“lunch”, “\\\”Show\\\””] }’ gets first unescaped to {“result”: … Read more

Split string on commas but ignore commas within double-quotes?

Lasse is right; it’s a comma separated value file, so you should use the csv module. A brief example: from csv import reader # test infile = [‘A,B,C,”D12121″,E,F,G,H,”I9,I8″,J,K’] # real is probably like # infile = open(‘filename’, ‘r’) # or use ‘with open(…) as infile:’ and indent the rest for line in reader(infile): print line … Read more