I have data stored similar to:
"lol data skadjs","ey how r u",hey,wowzor,"LOL HEY"
Does anyone know a decent way to unquote the data without ruining it.
Should come out like this:
Every method I've tried has failed (mainly due to one-words not getting quoted or commas in the actual data etc..
lol data skadjs
ey how r u
What are you trying to do, in a bit more "helicopter view"?
Most likely, you'll have to read the whole line in, and I can't think of a parser that will automatically respect quoted strings with commas and split the rest where there are commas, so you'll have to write your own parser. Not a very complex one, just keep track whether the text is in a quote or not. When you see a comma, you check if you are in quotes or not, and decide based on that if you need to start on the next string or not.
It's a simple state machine. If you see a quote when you are not inside quotes, you change states to be inside quotes. If you see a comma and you are inside quotes, ignore it. If you see a quote and you are inside quotes, then you are no longer inside quotes. If you see a comma and you are not inside quotes, then that's the end of a token.
dont know if this help: first, run through the string to check if the amount of quotes is even, if not, return an error or something.
Alternatively, parse the string as you go alon, and if you hit end of line with the state "in quotes" then you issue an error - since either way you'll have to parse the string, you might just as well do the error checking in the parser, rather than first walk through the string, and then walk it again.
Originally Posted by hdragon