android - 为什么我不能从变量中删除 div 标签?
问题描述
我正在尝试使用Jsoup库从变量中删除 div 标签,但它不适用于我。
代码
String test = "<div>hey</div>";
Document doc = Jsoup.parse(test);
doc.select("div").remove();
Log.w("log",test);
结果
2019-08-30 19:25:24.206 314-3434/com.test.app W/log: <div>hey</div>
解决方案
为什么不使用String.replace()
方法?例如:
String test = "<div>Hey<div>";
String newTest = test.replace("<div>", "");
或者尝试使用 JSoup 删除,
doc.getElementsByTag("div").remove();
推荐阅读
- c++ - SFML 打开多个窗口:不会让我一次打开两个以上的窗口
- r - 换行列标题文本,column_spec 不适用于 kable_styling
- html - 图像收缩后垂直弹性盒的横轴大小
- postgresql - 部署到 Elastic beanstalk 的 Jboss 单容器无法连接到远程数据库
- java - 为什么我的 Thread.sleep 在 CompletableFuture 中结束我的进程?
- java - 使用 java 将对象放入 S3 但没有从控制台看到任何对象
- c - 早期破坏者和命名寄存器
- python - IDLE 没有打开和读取文本文件
- python - Scrapy 登录然后从微博抓取数据
- javascript - 有人可以就我的 Axios 发布请求提供建议吗?