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>?
- I want to check if String1 ends with String2.
- If it does end with String2 , then I want to replace remove string2 from string1.
- So n the above case the text in String1 does end with the text in String2.( though the html is different for string1 and string2)
The output that I want is
String1= <img alt="" src="http://abcghgds.com/justin-bieber-ferns-650-430.jpg" width="650" height="430" />
I can't directly say if(String1.endsWith(String2)){}
as the html for both is different. So I'll first have to remove html and check if the text in string1 ends with text in string2 and then I want to replace the original string1 ( ie remove string 2 from string1 without altering any html of string1)
Here's what I have tried:
ans1 & ans2 are just texts and I use it only for comparison. I finally need to remove string2 from string1 if string1 rnds with string2. , but at the same time I don't want to alter the html is string1. I don't want all string1 to just be text.
String ans1= Jsoup.parse(string1).text();
String ans2 = Jsoup.parse(result1).text();
if(ans1.endsWith(ans2))
{
string1=string1.replace(result1, "");
}