Java HTML Encode toHtml(String str)

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

Description

to Html

License

Apache License

Declaration

public static String toHtml(String str) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String toHtml(String str) {
        if (str == null)
            return "";
        StringBuffer sb = new StringBuffer();
        int len = str.length();
        for (int i = 0; i < len; i++) {
            char c = str.charAt(i);
            switch (c) {
            case ' ':
                sb.append("&nbsp;");
                break;
            case '\n':
                sb.append("<br>");
                break;
            case '\r':
                break;
            case '\'':
                sb.append("&#39;");
                break;
            case '<':
                sb.append("&lt;");
                break;
            case '>':
                sb.append("&gt;");
                break;
            case '&':
                sb.append("&amp;");
                break;
            case '"':
                sb.append("&#34;");
                break;
            case '\\':
                sb.append("&#92;");
                break;
            default:
                sb.append(c);/* w  ww  . j a v  a  2s . co  m*/
            }
        }
        return sb.toString();
    }
}

Related

  1. toHtml(String p_str)
  2. toHTML(String plainText)
  3. toHTML(String rawText)
  4. toHTML(String s)
  5. toHtml(String s)
  6. toHtml(String str)
  7. toHtml(String str)
  8. toHtml(String str)
  9. toHTML(String string)