Android HTML Encode htmlencode(String str)

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

Description

htmlencode

Declaration

public static String htmlencode(String str) 

Method Source Code

//package com.java2s;

public class Main {
    public static String htmlencode(String str) {
        if (str == null) {
            return null;
        }//from   w  w w . j  a  v  a  2s . c  o m
        return replace("\"", "&quot;", replace("<", "&lt;", str));
    }

    public static String replace(String from, String to, String source) {
        if (source == null || source.length() == 0 || from == null
                || from.length() == 0 || to == null) {
            return source;
        }
        StringBuffer str = new StringBuffer("");
        int index = -1;
        int len = from.length();
        while ((index = source.indexOf(from)) != -1) {
            str.append(source.substring(0, index) + to);
            source = source.substring(index + len);
        }
        str.append(source);
        return str.toString();
    }
}

Related

  1. htmEncode(String input)
  2. replaceHTMLTags(final String source)
  3. encodeHtml(String to_encode)
  4. fromHTML(String textToTransform)
  5. htmlEncode(String stringToEncode)