简体   繁体   English

如何在Java中使用重复字符分割字符串

[英]How to split a string with recurrent characters in java

I'm trying to split a string of the following format (with x possible numbers in the lists) into two different strings : 我正在尝试将以下格式的字符串(列表中有x个可能的数字)拆分为两个不同的字符串:

"9 7 20 -3 4” “1 2 0 -6" “ 9 7 20 -3 4”“ 1 2 0 -6”

I know how to split a string, but only by one character (a space for example) 我知道如何分割字符串,但只能分割一个字符(例如空格)

I wouldn't know what to do to split this into two strings by their quotation marks. 我不知道该怎么用引号将其分成两个字符串。

And after having split these into two different strings, I don't know how to split the lists themselves into an array of numbers (since there is an x number of possible numbers). 在将它们拆分为两个不同的字符串之后,我不知道如何将列表本身拆分为一个数字数组(因为存在x个可能的数字)。

Do You mean to split with this regex ”\\\\s+“ : 您是否要使用此正则表达式”\\\\s+“进行拆分:

String str = "9 7 20 -3 4” “1 2 0 -6";
String spl[] = str.split("”\\s+“");

Outputs 输出

[9 7 20 -3 4, 1 2 0 -6]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM