Java HTML to String htmlToText(String html)

Here you can find the source of htmlToText(String html)

Description

Simply removes the <...> tags.

License

Open Source License

Parameter

Parameter Description
html HTML text

Declaration

public static String htmlToText(String html) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  ww w  . j a  va  2s  . co m
     * Simply removes the <...> tags. Period.
     *
     * @param html HTML text
     */
    public static String htmlToText(String html) {
        // Locals
        char ch = '\u0000';
        int idx = 0;
        int len = html.length();
        StringBuffer sb = new StringBuffer();

        // Conversion
        for (int i = 0; i < len; i++) {
            ch = html.charAt(i);

            // If this char is '<' then find the first '>' char
            // after it. Do not write the text between '<' and '>'
            // (both inclusive). Write the text found otherwise
            // to the buffer
            if (ch != '<') {
                sb.append(ch);
            } else {
                idx = html.indexOf('>', i + 1);
                if (idx != -1) {
                    i = idx;
                } else {
                    sb.append(html.substring(i, len));
                    i = len;
                }
            }
        }

        // Return
        return sb.toString();
    }
}

Related

  1. htmlToStr(String htmlStr, int max_count)
  2. htmlToString(String aS_Text)
  3. htmlToString(String s)
  4. htmlToString(String string)
  5. htmlToText(String html)
  6. htmlToText(String input)
  7. htmlToText(String sHTML)
  8. toText(String html)
  9. toText(String html)