String1:
<img alt="" src="http://abcghgds.com/justin-bieber-ferns-650-430.jpg" width="650" height="430" /> Have you seen <a href="http://www.abcdefg.com/between_two_ferns" target="_blank">Between Two Ferns</a>?
Result1:
Have you seen <a style = "display:inline" href="http://www.abcdefg.com/between_two_ferns" target="_blank">Between Two Ferns</a>?
我正在尝试检查文本是否以 string1 中的文本结尾。如果是这样,那么我想用“”替换 String1 中的文本(与 result1 中的文本相同)
所以基本上在上面的情况下,预期的输出将是:(因为 string1 中的文本以 result1 中的文本结尾)我想要这个输出
String 1 = <img alt="" src="http://abcghgds.com/justin-bieber-ferns-650-430.jpg" width="650" height="430" />
尽管文本相同,但其包装到的关联 html 不同。所以我真的无法取代它。
这是我尝试过的
String ans1= Jsoup.parse(string1).text();
String ans2 = Jsoup.parse(result1).text();
if(ans1.endsWith(ans2))
{
string1=string1.replace(result1, ""); ---> // This does not work as I have to replace the text as well as the html from the original string to get the desired op. How do I do it?
}
你忘记写入数据,你所做的只是读取和操作数据
String ans1= Jsoup.parse(string1).text();
String ans2 = Jsoup.parse(result1).text();
if(ans1.endsWith(ans2))
{
string1=string1.replace(result1, "");
}
Jsoup.parse(ans1).text(string1);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)