简体   繁体   中英

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 :

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

Do You mean to split with this regex ”\\\\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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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