How to remove html tag from string?

public String removeHTMLTag(String html) {
        String finalString = "";
        try {
            finalString = html.replaceAll("\\<.*?>", "");

          
            finalString = finalString.replaceAll("\\&.*?;", "");
            finalString = finalString.replace("\r\n", " ");
            finalString = finalString.replace("\n", " ");
            finalString = finalString.replace("\t", " ");
            finalString = finalString.replaceAll("\\<.*?>", "");
            finalString = finalString.replaceAll("\\s+", " ");
            finalString = finalString.trim();
            // System.out.println(finalString);
            return finalString;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return html;
    }

Comments

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

How to capture finger prints in java

Shallow Copy Deep Copy Java example