0

I have strings like this

"'Hello, how are you?','string',123"

I need to split it so it looks like

["'Hello, how are you'", "'string'", "123"]

But when I use String.split(","), I get this:

["'Hello", "how are you'","'string'","123"]

How can I split by comma but only when it's not between single quotes?

code511788465541441
  • 20,207
  • 61
  • 174
  • 298
  • I guess you have to look into https://en.wikipedia.org/wiki/Natural_language_processing then. I think: too broad for a simple question here. – GhostCat Mar 27 '17 at 19:36
  • @yshavit yes i can use a third party parser but it isn't JSON – code511788465541441 Mar 27 '17 at 19:36
  • not really even language processing, just a boolean for "am I in a quote right now?" and an iteration of the string (using a StringBuilder) – Rogue Mar 27 '17 at 19:37
  • You will need your own split function. you need to maintain a bool for the within qoutes, so you know if you ignore your comma or not. – nabuchodonossor Mar 27 '17 at 19:38
  • @Rogue maybe, maybe not. Maybe the 6K reputation of the questioner made me think that his problem can't be that trivial ;-) – GhostCat Mar 27 '17 at 19:38

0 Answers0