Reputation: 2134
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
Upvotes: 1
Views: 1379
Reputation: 61
You can split on comma surrounded by quotes, then replace leading/trailing quotation marks with empty strings. If you want to have it surrounded with quotes, you can easily add it after.
Upvotes: 0
Reputation: 2134
Yes I got the split
String []ip_variables=line.split("\",");
This one worked for me
Upvotes: 0
Reputation: 49803
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.
Upvotes: 1