Josephine Josephine - 1 month ago 21
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) {
System.out.println(s);
}


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

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++)
{
   System.out.println(str1[iCount]);
}