I have a string like this:
"Video or movie" "parent" "Media or entertainment" "1" "1" "1" "0" "0"
I would like to split it by the spaces but the space inside the quote should be ignored. So the splitted strings should be:
"Video or movie"
"parent"
"Media or entertainment"
"1"
...
The language is java.
Use method String. split() It returns an array of String, splitted by the character you specified.
The first method to print the double quotes with the string uses an escape sequence, which is a backslash ( \ ) with a character. It is sometimes also called an escape character.
split("\\s+") will split the string into string of array with separator as space or multiple spaces. \s+ is a regular expression for one or more spaces.
this should do the job for you:
final String s = "\"Video or movie\" \"parent\" \"Media or entertainment\" \"1\" \"1\" \"1\" \"0\" \"0\"";
final String[] t = s.split("(?<=\") *(?=\")");
for (final String x : t) {
System.out.println(x);
}
output:
"Video or movie"
"parent"
"Media or entertainment"
"1"
"1"
"1"
"0"
"0"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With