Android how to remove new line and spaces and all html tags from String

Step 1: 

compile 'org.jsoup:jsoup:1.11.3'

add jsonup gradle and sync. 

Step 2 : 
create a method
public static String html2text(String html) {
    return Jsoup.parse(html).text();

Step 3 : 
implement this
String descriptionRawText = "raw text";
String descriptionFinalText = descriptionRawText.replace("\n", "").replaceAll("\\<[^>]*>","").replace("\r", "");
String htmlConvertedText = html2text(descriptionFinalText);

Done :) 

Leave a Reply

Your email address will not be published. Required fields are marked *