Java HTML Encode toHtmlString(String input)

Here you can find the source of toHtmlString(String input)

Description

to Html String

License

Apache License

Declaration

public static String toHtmlString(String input) 

Method Source Code

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

public class Main {
    public static String toHtmlString(String input) {
        if ((input == null) || (input.trim().length() == 0)) {
            return input;
        }/*from w ww .j  av  a  2 s .co  m*/

        StringBuffer result = new StringBuffer();
        char tmp;
        char lstchar = ' ';

        for (int i = 0; i < input.length(); i++) {
            tmp = input.charAt(i);

            if (((int) tmp) == 13) {
                result.append("<br>");
                lstchar = tmp;
            } else if (((int) tmp) == 10) {
                if (((int) lstchar) == 13) {
                    result.append("");
                } else {
                    result.append("<br>");
                }
            } else {
                result.append(input.charAt(i));
            }
        }

        return result.toString();
    }
}

Related

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