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代码。这是我的代码。似乎正确,但是返回的是表(子字符串),而不是提取的文本。有人知道为什么吗?

最佳答案

您必须使用新的String对象作为TextView的源。更改此:

WORK.setText(htmlString);


到以下内容:

WORK.setText(noHTMLString);

10-05 21:07