Split String at Space ,Except if it is not in double qoutes
public class Main {
public static void main(String[] args) {
String str=
"abc \"peter micheal\" Jean \"Patrick David\" Richards";
String[] tempArr = str.split("[ ]+(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
for(String string : tempArr) {
System.out.println(string);
}
}
}
You can use online java compiler such as THIS
to verify usability.
This will help you to avoid chances of using wrong solution and save your time.
Output:
abc
"peter micheal"
Jean
"Patrick David"
Richards
No comments:
Post a Comment