Java HTML Encode htmlEncode(String str)

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

Description

html Encode

License

Open Source License

Declaration

public static String htmlEncode(String str) 

Method Source Code

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

public class Main {
    public static String htmlEncode(String str) {
        if (str != null) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < str.length(); i++) {
                char c = str.charAt(i);
                if (c == '<') {
                    sb.append("&lt;");
                } else {
                    sb.append(c);/*  ww  w . j a  v a  2s .c o  m*/
                }
            }
            return sb.toString();

        } else {
            return null;
        }
    }

    public static char charAt(String str, int index) {
        if (str != null && str.length() > index) {
            return str.charAt(index);
        } else {
            return '\0';
        }
    }
}

Related

  1. htmlEncode(String s, boolean encodeSpecialChars)
  2. htmlEncode(String s, boolean encodeWS)
  3. HtmlEncode(String str)
  4. HTMLEncode(String str)
  5. htmlEncode(String str)
  6. htmlEncode(String str)
  7. htmlEncode(String str)
  8. htmlEncode(String string)
  9. HTMLEncode(String string)