// Method 1 import Java. util. regEx. pattern; import Java. util. regEx. matcher ;... // 4 different combinaisonspattern CRLF = pattern. compile ("(\ r \ n | \ r | \ n \ r)"); matcher M = CRLF. matcher (mystring); If (M. find () {newstring = m. replaceall ("<br>") ;}// method 2 newstring = mystring. replaceall ("(\ r \ n | \ r | \ n \ r)", "<br> ");
Test
Import Java. util. regEx. matcher; import Java. util. regEx. pattern; public class stringtest {public static string SSS (string mystring) {string newstring = NULL; pattern CRLF = pattern. compile ("(\ r \ n | \ r | \ n \ r)"); matcher M = CRLF. matcher (mystring); If (M. find () {newstring = m. replaceall ("<br>");} return newstring;}/*** @ Param ARGs */public static void main (string [] ARGs) {string AAA = "sdfsfdsfsdf \ r \ n, dsfsdfsdf \ r \ n"; // AAA. replace ("S", "x"); string newstr = SSS (AAA); system. out. println (newstr );}}