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

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);
productDesc.setText(Html.fromHtml(String.valueOf(Html.fromHtml(htmlConvertedText))));



Done :) 







Leave a Reply

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