Java HTML htmlLineBreaks(String s)

Here you can find the source of htmlLineBreaks(String s)

Description

Convert newlines in the string into <br/> tags.

License

Open Source License

Parameter

Parameter Description
s the string to process.

Return

processed string.

Declaration

public static String htmlLineBreaks(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   www . ja v  a  2s .  c  o  m
     * Convert newlines in the string into &lt;br/&gt; tags.
     *
     * @param s the string to process.
     * @return processed string.
     */
    public static String htmlLineBreaks(String s) {
        if (s == null) {
            return "";
        }
        StringBuilder out = new StringBuilder();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '\n') {
                out.append("<br />");
            } else if (chars[i] == '\r') {
                if (i < chars.length - 1 && chars[i + 1] == '\n') {
                    i++;
                }
                out.append("<br />");
            } else {
                out.append(chars[i]);
            }
        }
        return out.toString();
    }
}

Related

  1. htmlFormatText(String line1, String line2)
  2. htmlHashTag(final String tagName)
  3. htmlHeaderGen(String errorMsg)
  4. htmlify(String str)
  5. htmlItemName(int itemId)
  6. htmlLink(String url, String linkName)
  7. htmlNewline(String text)
  8. htmlSafe(String field)
  9. htmlSafe(String value)