Josephine Josephine - 7 months ago 70
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!!!


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++)