Josephine Josephine - 1 year ago 97
Java Question

Splitting string by multiple delimiters

I have a string of names. I am looking to split it based on names between double quotes. I used the following code to split the names.

String []splitterString=str.split("\"");

for (String s : splitterString) {

I get the output as:

Hossain, Ziaul
Sathiaseelan, Arjuna
Secchi, Raffaello
Fairhurst, Gorry

I need to store just the names from these. I am not sure how to do that.

This is the string:
["Hossain, Ziaul","Sathiaseelan, Arjuna","Secchi, Raffaello","Fairhurst, Gorry"]

Thanks for the help!!!

Answer Source

I think following solution may help you out :-

String str = "[\"Hossain, Ziaul\",\"Sathiaseelan, Arjuna\",\"Secchi, Raffaello\",\"Fairhurst, Gorry\"]";

String [] str1 = str.split("\\[\"|\",\"|\"\\]");
for (int iCount = 0; iCount < str1.length; iCount++)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download