java 在引号上分割/拆分字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3434348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:50:46  来源:igfitidea点击:

Divide/split a string on quotation marks

javastringsplitcharacter

提问by Stole

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. .

  1. 我会

  2. 一定

  3. 喜欢

  4. 上学

  5. .

回答by Konrad Rudolph

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

如果您的意思是引号 ( ") 而不是省略号,最简单的解决方案是使用String.split

String text = "I would \"surely\" like to \"go to school\".";
String[] result = text.split("\"");