asj177 asj177 - 1 year ago 92
Java Question

Split a string with double quotes -Java

I have a String

"OWIRH","ABCDHW","KR","Korea, Republic of","11","Seoul-t'ukpyolsi","Seoul","","37.598500","126.978300","HyosungITX","HyosungITX"

I want to split this string such as

s[3]="Korea, Republic of"

How do I apply such a (delimiter)split in java

Answer Source

If you split on ", then every other string in the resulting list will be one you want; the others will be commas or leading/trailing blanks. You can then build the array you want from that.

An alternative would be to split on "," (not just the comma, but the comma in quotes); that would be very close to what you want, but the first item would have a leading " and the last a trailing one.