replace \n and \r\n with
in java

后端 未结 7 1493
余生分开走
余生分开走 2020-11-29 04:49

This has been asked several times for several languages but I can\'t get it to work. I have a string like this

String str = \"This is a string.\\nThis is a l         


        
7条回答
  •  臣服心动
    2020-11-29 05:42

    That should work, but don't kill yourself trying to figure it out. Just use 2 passes.

    str  = str.replaceAll("(\r\n)", "
    "); str = str.replaceAll("(\n)", "
    ");

    Disclaimer: this is not very efficient.

提交回复
热议问题