Java HTML htmlNewline(String text)

Here you can find the source of htmlNewline(String text)

Description

Replaces common newline characters like \n, \r, \r\n to the HTML line break tag br.

License

Open Source License

Parameter

Parameter Description
text the text to substitute.

Return

the substituted text.

Declaration

public static String htmlNewline(String text) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from www  . j a va  2 s  .com
     * Replaces common newline characters like \n, \r, \r\n to the HTML line
     * break tag br.
     * 
     * @param text the text to substitute.
     * @return the substituted text.
     */
    public static String htmlNewline(String text) {
        if (text == null || text.trim().isEmpty()) {
            return null;
        }

        return text.replaceAll("(\n|\r|\r\n)", "<br>");
    }
}

Related

  1. htmlHeaderGen(String errorMsg)
  2. htmlify(String str)
  3. htmlItemName(int itemId)
  4. htmlLineBreaks(String s)
  5. htmlLink(String url, String linkName)
  6. htmlSafe(String field)
  7. htmlSafe(String value)
  8. htmlSize(String str)
  9. htmlString(String str)