gpt4 book ai didi

java - 从源代码中剥离 html 标签

转载 作者:行者123 更新时间:2023-12-02 07:11:13 25 4
gpt4 key购买 nike

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);

关于java - 从源代码中剥离 html 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15502840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com