0

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'm trying to check if the text is string1 ends with the text in result1. If it does then I want to replace the text(which is same as text in result1) in String1 with ""

So basically in the above case the expected output would be:(As text in string1 ends with the text in result1) I want this output

String 1 = <img alt="" src="http://abcghgds.com/justin-bieber-ferns-650-430.jpg" width="650" height="430" /> 

Though the text is same, the associated html it is wrapped into is different. So I can't really replace it .

Here's what I tried

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? 
    }

1 Answer 1

2

you forgot to write data all you did was read and manipulate data

 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);
Sign up to request clarification or add additional context in comments.

1 Comment

no. The thing is that result1 wont be there in string1 as both have different html but same text. So it wont get replaced. You getting my point?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.