Remove all empty lines

后端 未结 7 1622
误落风尘
误落风尘 2020-11-27 17:22

I thought that wasn\'t that hard to do, but I want to remove all empty lines (or lines just containing blanks and tabs in Java) with String.replaceAll.

My regex look

7条回答
  •  攒了一身酷
    2020-11-27 18:14

    You can remove empty lines from your code using the following code:

    String test = plainTextWithEmptyLines.replaceAll("[\\\r\\\n]+","");
    

    Here, plainTextWithEmptyLines denotes the string having the empty lines. [\\\r\\\n] is the regex pattern which is used to identify empty line breaks.

提交回复
热议问题