[英]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("\'", "'");
noHTMLString = noHTMLString.replaceAll("\"", """);
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.