Real'sHowTo AddThis Feed Button
Custom Search

Replace \r\n with the <br> tagTag(s): String/Number

This can be done easily a regular expression.


import java.util.regex.Pattern;
import java.util.regex.Matcher;

// 4 different combinaisons
Pattern CRLF = Pattern.compile("(\r\n|\r|\n|\n\r)");
Matcher m = CRLF.matcher(myString);
if (m.find()) {
  newString = m.replaceAll("<br>");
or use the String.replaceAll(regex,replacement) method which is doing basically the same thing.
newString = myString.replaceAll("(\r\n|\r|\n|\n\r)", "<br>");

blog comments powered by Disqus

If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2015
[ home ]