Find and replace all NewLine or BreakLine characters with \n in a String - Platform independent

后端 未结 3 1653
深忆病人
深忆病人 2020-12-09 19:58

I am looking for a proper and robust way to find and replace all newline or breakline chars from a String independent of any OS platfo

3条回答
  •  旧巷少年郎
    2020-12-09 20:13

    If you want literal \n then following should work:

    String repl = str.replaceAll("(\\r|\\n|\\r\\n)+", "\\\\n")
    

提交回复
热议问题