Java HTML Encode toHTMLString(String in)

Here you can find the source of toHTMLString(String in)

Description

to HTML String

License

Open Source License

Declaration

public static String toHTMLString(String in) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String toHTMLString(String in) {
        if (in == null || in.length() <= 0) {
            return "";
        }/* ww  w  .  j  av a2  s. com*/

        StringBuffer out = new StringBuffer();
        for (int i = 0; i < in.length(); i++) {
            char c = in.charAt(i);
            if (c == '\'')
                out.append("'");
            else if (c == '\"')
                out.append("");
            else if (c == '<')
                out.append("&lt;");
            else if (c == '>')
                out.append("&gt;");
            else if (c == '&')
                out.append("&amp;");
            else if (c == ' ')
                out.append("&nbsp;");
            else if (c == '\n')
                out.append("<br>");
            else if (c == '\r')
                continue;
            else
                out.append(c);
        }
        return out.toString();
    }
}

Related

  1. toHtmlCR(String text)
  2. toHTMLEncode(String string)
  3. toHTMLEscapedText(String s)
  4. toHtmlInput(String str)
  5. toHtmlLine(String input)
  6. toHtmlString(String input)
  7. toHTMLString(String org)
  8. toHtmlString(String s)
  9. toHTMLString(String str)