replace \n and \r\n with
in java

后端 未结 7 1462
余生分开走
余生分开走 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:25

    It works for me. The Java code works exactly as you wrote it. In the tester, the input string should be:

    This is a string.
    This is a long string.
    

    ...with a real linefeed. You can't use:

    This is a string.\nThis is a long string.
    

    ...because it treats \n as the literal sequence backslash 'n'.

提交回复
热议问题