Java HTML Escape htmlEscape(String str)

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

Description

html Escape

License

Open Source License

Declaration

public static String htmlEscape(String str) 

Method Source Code

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

public class Main {
    public static String htmlEscape(String str) {
        StringBuilder esc = new StringBuilder();
        for (int i = 0; i < str.length(); ++i) {
            final char c = str.charAt(i);
            switch (c) {
            case '<':
                esc.append("&lt;");
                break;
            case '>':
                esc.append("&gt;");
                break;
            case '&':
                esc.append("&amp;");
                break;
            case '"':
                esc.append("&quot;");
                break;
            default:
                esc.append(c);/*from  w w w.ja  va 2  s.c om*/
            }
        }
        return esc.toString();
    }
}

Related

  1. htmlEscape(String S)
  2. htmlEscape(String s)
  3. htmlEscape(String s)
  4. htmlescape(String s)
  5. htmlEscape(String source)
  6. htmlEscape(String str)
  7. htmlEscape(String str)
  8. htmlEscape(String string)
  9. htmlEscape(String tag)