Hacker News new | ask | show | jobs
by hasmanean 798 days ago
That’s still multiple lines of code.

Here’s one in c++ that uses only a single line of code (excluding function headers)

// How do I format this as code?

vector<string> split( const string& s) { return accumulate(s.begin(), s.end(), vector<string>(1), [=](auto acc, char c) { if (c == ‘,’){ acc.push_back(string()); } else { acc.back( ) += c; } return acc; } ); }

1 comments

Does it parse this, though?

  "Verne, Jules", "20,000 leagues under the sea"
Wrap it in a second function that parses out quotes and bit-stuffs the commas with something else.