⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 html2text.java

📁 Eclipse的插件
💻 JAVA
字号:
package samples.services.html2text;

public class HTML2Text {
    public static String convertHTML2Text(String html) {
	// simple algorithm, not intended for any real conversion

	// if we strip out anything between '<' and '>'
	// (inclusive of those characters) 
	// it works for many cases and is simple,
	// so we will do that

	StringBuffer cleanString = new StringBuffer();
	boolean tagsExist = true;
	int endOfLastTag = 0;
	while(tagsExist) {
	    int startOfNextTag = html.indexOf('<',endOfLastTag);
	    int endOfNextTag = html.indexOf('>',startOfNextTag);
	    if (startOfNextTag==-1 || endOfNextTag==-1) {
		// no more tags
		tagsExist = false;
	    } else {
		// we have a tag
		// copy the text from the end of the last tag
		// to the start of this tag
		// that is to say strip out the stuff within the tag itself
		cleanString.append(html.substring(endOfLastTag,startOfNextTag));
		endOfLastTag = endOfNextTag+1;
	    }
	}
	// add the text from the end of the last tag until the end of the string
	cleanString.append(html.substring(endOfLastTag));
	return cleanString.toString();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -