[英]How to split a String my Empty lines in java
can anyone help me how to split string by empty lines? 谁能帮我如何用空行分割字符串? for example i have following string
例如我有以下字符串
abc def ghk
122 saf fsaf
sfa fasf
afsf
i want to split above string by empty lines and output should be as follows 我想用空行在字符串上方分割,输出应如下
string[0] = "abc def ghk
122 saf fsaf"
String[1]="sfa fasf"
String[2]="afsf"
Thanks in advance 提前致谢
You can split the string on a newline that has only whitespace until the next newline: 您可以在只有空格的换行符上分割字符串,直到下一个换行符为止:
String input = "abc def ghk\n122 saf fsaf\n\nsfa fasf afsf";
String[] split = input.split("\n\\s*\n");
System.out.println(split[0]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.