簡體   English   中英

從源代碼中剝離html標記

[英]Stripping html tags from source code

HTML = EntityUtils.toString(response.getEntity());
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String ResponseBody = httpclient.execute(httppost, responseHandler);
table = ResponseBody.substring(ResponseBody.indexOf("<table border=\"1\" cellpadding=\"0\" width=\"100%\" cellspacing=\"0\">"));
table = table.substring(0, table.indexOf("</table>"));  

String htmlString = table;
String noHTMLString = htmlString.replaceAll("\\<.*?\\>", "");
noHTMLString = noHTMLString.replaceAll("\r", "<br/>");
noHTMLString = noHTMLString.replaceAll("\n", " ");
noHTMLString = noHTMLString.replaceAll("\'", "&#39;");
noHTMLString = noHTMLString.replaceAll("\"", "&quot;");

TextView WORK = (TextView) findViewById(R.id.HTML);
WORK.setText(htmlString); 

我正在使用正則表達式來提取HTML代碼。 這是我的代碼。 看起來是正確的但是表(substring)是返回的而不是提取的文本。 有誰知道為什么???

您必須使用新的String對象作為TextView的源。 改變這個:

WORK.setText(htmlString);

以下內容:

WORK.setText(noHTMLString);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM