Replace new line/return with space using regex

前端 未结 7 1744
醉梦人生
醉梦人生 2020-12-24 06:36

Pretty basic question for someone who knows.

Instead of getting from

\"This is my text. 

And here is a ne         


        
相关标签:
7条回答
  • 2020-12-24 07:10

    The new line separator is different for different OS-es - '\r\n' for Windows and '\n' for Linux.

    To be safe, you can use regex pattern \R - the linebreak matcher introduced with Java 8:

    String inlinedText = text.replaceAll("\\R", " ");
    
    0 讨论(0)
提交回复
热议问题