[英]Java replace in string html img tags
I am parsing a json feed and displaying its content in a android webview. 我正在解析json feed,并在android webview中显示其内容。 Everything works great. 一切正常。 But now i want to hide all img tags in that android webview. 但是现在我想在该android webview中隐藏所有img标签。
The problem is that the content in the webview is showen dynamically, that means i don't know the img tag parameters. 问题在于Web视图中的内容是动态显示的,这意味着我不知道img标签参数。 So i need something to replace everything in that string that begins with 所以我需要一些东西来替换以
<img ... >
and ends with 并以
</img>
How can I do that? 我怎样才能做到这一点?
Because none of these answeres worked for me, i finally decided to use jsoup to filter and remove all img tags. 因为这些答案都不适合我,所以我最终决定使用jsoup过滤并删除所有img标签。
using jsop was a little bit complex but it worked!! 使用jsop有点复杂,但是有效!!
EDIT Here is an example java code 编辑这是一个示例Java代码
String content = "<h1>title</h1><img src="http://..."></img>";
if(content != null) {
Document document = Jsoup.parse(content);
document.select("img").remove();
content = document.toString();
}
如果您自己处理String并将其设置为webview,则假定您的内容位于名为oldWebViewContent
的String中,然后尝试执行以下操作:
String webViewContentExcludeImage = oldWebViewContent.replaceAll("<img .*?</img>","");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.