asj177 asj177 - 5 months ago 20
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

String[]s
s[0]="OWIRH"
s[1]="ABCDHW"
s[2]="KR"
s[3]="Korea, Republic of"


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

Answer

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.