Java HTML Encode toHtmlText(String s)

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

Description

Description of the Method

License

Open Source License

Parameter

Parameter Description
s Description of the Parameter

Return

Description of the Return Value

Declaration

public static String toHtmlText(String s) 

Method Source Code

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

public class Main {
    /**//from   w  w w.  ja  va 2 s  .  c o m
     * Description of the Method
     *
     * @param s Description of the Parameter
     * @return Description of the Return Value
     */
    public static String toHtmlText(String s) {
        s = replace(s, "<br>\r\n", "<br>");
        s = replace(s, "\r\n", "<br>");
        return s;
    }

    /**
     * Description of the Method
     *
     * @param str Description of Parameter
     * @param o   Description of Parameter
     * @param n   Description of Parameter
     * @return Description of the Returned Value
     */
    public static String replace(String str, String o, String n) {
        boolean all = true;
        if (str != null && o != null && o.length() > 0 && n != null) {
            StringBuffer result = null;
            int oldpos = 0;
            do {
                int pos = str.indexOf(o, oldpos);
                if (pos < 0) {
                    break;
                }
                if (result == null) {
                    result = new StringBuffer();
                }
                result.append(str.substring(oldpos, pos));
                result.append(n);
                pos += o.length();
                oldpos = pos;
            } while (all);
            if (oldpos == 0) {
                return str;
            } else {
                result.append(str.substring(oldpos));
                return result.toString();
            }
        } else {
            return str;
        }
    }

    /**
     * Description of the Method
     *
     * @param s Description of Parameter
     * @return Description of the Returned Value
     */
    public static String toString(String s) {
        if (s != null) {
            return (s);
        } else {
            return ("");
        }
    }
}

Related

  1. toHTMLString(String in)
  2. toHtmlString(String input)
  3. toHTMLString(String org)
  4. toHtmlString(String s)
  5. toHTMLString(String str)
  6. toHtmlText(String text)
  7. toHtmlTitle(final String title)
  8. toHtmlUrl(String url, String displayLabel)
  9. toHtmlValue(String s)