How To Remove HTML Element Of String?
I want to remove HTML of string in Java.
Task Details
Date Created: 01/06/2014 07:55pm
Task Details
Date Created: 01/06/2014 07:55pm
Solution 1:
Maybe this will work:
String noHTMLString = htmlString.replaceAll("\\<.*?>","");
It uses regular expressions to remove all HTML tags in a string.
More specifically, it removes all XML like tags from a string. So <1234> will be removed even though it is not a valid HTML tag. But its good for most intents and purpouses.
Hope this helps.
This is actually dead simple with Jsoup.
public static String html2text(String html) {
return Jsoup.parse(html).text();
}
Solution 2:
You can use Jsoup library for it.
String str="<h3>My Text</h3>";
System.out.println(Jsoup.parse(str).text());
The above code strip all htms tags and give text left as output
Post a Comment for "How To Remove HTML Element Of String?"