HTML String tags are not replaced (Android) -


i have following piece of html:

<p>bla bla bla...</p> <p><strong>4. others</strong></p> <p> </p> 

it contains random <p> </p> tag combination needs filtered out in android app. i'm using following java code it:

string html = object.get("content").tostring(); // html html = html.replace("<p> </p>", ""); html = html.replace("<p></p>", ""); html = html.replace("<p><span></span></p>", ""); content.settext(html.fromhtml(html)); 

however, when debug , put break point on replace functions, doesn't replace strings. have useless <p> tags don't want. how solve this?

it contains random

tag combination needs filtered out in android app. need replace separately. because replace() function works case-sensitive , sequential strings. so, use below code

string html = object.get("content").tostring().trim(); // html html = html.replace("<p>", ""); html = html.replace("</p>", ""); html = html.replace("<span>", ""); html = html.replace("</span>", ""); content.settext(html.fromhtml(html)); 

instead of joint string in replace()

string html = object.get("content").tostring(); // html html = html.replace("<p> </p>", ""); html = html.replace("<p></p>", ""); html = html.replace("<p><span></span></p>", ""); content.settext(html.fromhtml(html)); 

you result per want.

note: but, remember anytime want replace character/string replace sequential case-sensitive. because gives exact result.


Comments