Java HTML Encode toHtml(String str)

Here you can find the source of toHtml(String str)

Description

to Html

License

Open Source License

Declaration

public static String toHtml(String str) 

Method Source Code

//package com.java2s;

public class Main {

    public static String toHtml(String str) {
        if (str == null)
            return "";

        String html = new String(str);

        html = toHtmlInput(html);/*from  w  ww . j a  v  a 2  s . c  o m*/
        html = html.replaceAll("\r\n", "\n");
        html = html.replaceAll("\n", "<br>\n");
        html = html.replaceAll("\t", "    ");
        html = html.replaceAll("  ", " &nbsp;");

        return html;
    }

    public static String toHtmlInput(String str) {
        if (str == null)
            return "";

        String html = new String(str);

        //        html = html.replaceAll("&", "&amp;");
        html = html.replaceAll("<", "&lt;");
        html = html.replaceAll(">", "&gt;");
        //        html = html.replaceAll("\"", "&quot;");

        return html;
    }
}

Related

  1. toHtml(String s)
  2. toHTML(String s)
  3. toHtml(String str)
  4. toHtml(String str)
  5. toHtml(String str)
  6. toHTML(String string)
  7. toHTML(String text)
  8. toHtml(String text)
  9. toHtml(String trace)