Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Divide/split a string on quotation marks

I have the following string:

I would "surely" like to "go to school".

Now, I would like to split this string at the ellipses, that is i would like to get the following output:

  1. I would

  2. surely

  3. like to

  4. go to school

  5. .

like image 526
Stole Avatar asked Aug 08 '10 12:08

Stole


People also ask

How do you split a string with a quote?

Use method String. split() It returns an array of String, splitted by the character you specified. Save this answer.

How do you split words in a string?

The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.

How do you escape quotation marks in a string?

How to Escape Quotes in a String. To add quoted strings inside of strings, you need to escape the quotation marks. This happens by placing a backslash ( \ ) before the escaped character.


1 Answers

I case you meant quotation mark (") instead of ellipsis, the easiest solution is to use String.split:

String text = "I would \"surely\" like to \"go to school\".";
String[] result = text.split("\"");
like image 106
Konrad Rudolph Avatar answered Sep 28 '22 07:09

Konrad Rudolph