I'm reading in a file in Java and want to split each line by the value inside quotation marks. For example, a line would be...
"100","this, is","a","test"
I would like the array to look like..
[0] = 100
[1] = this, is
[2] = a
[3] = test
I normally split by comma, but since some of the fields include a comma (position 1 in the example above) it's not really suitable.
Thanks.
You can split it the following way:
String input = "\"100\",\"this, is\",\"a\",\"test\"";
for (String s:input.split("\"(,\")*")) {
System.out.println(s);
}
Output
100
this, is
a
test
Note The first array element will be empty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With