I have a string like
some text <p>any text</p>
from which I need to remove the part
<p>any text</p>
and as a result, get the string
some text
I found some sample code from a tutorial to work with strings, but I don’t understand how it works. I’m a newbie in coding and it’s hard because I don’t know English.
private String description;
public void setDescription(String description) {
this.description = description;
if (description.contains("<p>")) {
String musor = description.substring(description.indexOf("<p>"));
String cleanUp = musor.substring(0, musor.indexOf("</p>")+1);
musor = musor.substring(musor.indexOf("<p>"));
this.description = this.description.replace(cleanUp, "");
}
}
You can use regular expressions which can do the trick.
Replaces all
<p>-tags and their contents with. (See also http://www.regular-expressions.info/.)I guess that there are a lot of libraries, which can do the same or even more.