Here you can find the source of htmlToText(String html)
Parameter | Description |
---|---|
html | HTML text |
public static String htmlToText(String html)
//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(); } }