Now you want to take a part of the content of the article as a description on the page, as shown in the following illustration:
The data in the red box is part of the content of the article, but the content of the article will be stored in the format of HTML code, etc.
To display the normal need to filter the HTML tags, the code is as follows:
public string Delhtmltag (string htmlstr) {
string regex_style= ' <style[^>]*?>[\\s\\S]*?<\\/style> "; The regular expression
String regex_html= "<[^>]+>" that defines the style;//defines the regular expression pattern P_style=pattern.compile for HTML tags
( regex_style,pattern.case_insensitive);
Matcher M_style=p_style.matcher (HTMLSTR);
Htmlstr=m_style.replaceall (""); Filter style label pattern
p_html=pattern.compile (regex_html,pattern.case_insensitive);
Matcher M_html=p_html.matcher (HTMLSTR);
Htmlstr=m_html.replaceall (""); Filter HTML tags
htmlstr=htmlstr.replace ("", "");
Htmlstr=htmlstr.replaceall ("\\s*|\t|\r|\n", "");
Htmlstr=htmlstr.replace ("" "," ");
Htmlstr=htmlstr.replace ("" "," ");
Htmlstr=htmlstr.replaceall ("", "");
return Htmlstr.trim (); Returns a text string
The program simply calls:
String content = delhtmltag (content);