• If you want to remove html tags from a string in java you need to use regex.
  • Using java regex we can trim/remove html tags from given string.
  • Lets see a java example program on how can we remove html code or html tags from a string in java.
  • Input String : <B>hello</B>
  • output: hello



#1: Java Example program to remove html tags from a string

  1. package com.instanceofjava.removehtmltags;
  2. /**
  3.  * @author www.Instanceofjava.com
  4.  * @category interview programs
  5.  * 
  6.  * Description: java convert html to plain text/ trim html code from string in java
  7.  *
  8.  */
  9. public class RemoveHtmlTags {

  10. public static void main(String[] args) {
  11. String htmlStr = "<p>Java Program to remove html tags from a String</p>";
  12.         System.out.println(htmlStr);
  13.         htmlStr = htmlStr.replaceAll("\\<.*?\\>", "");
  14.         System.out.println(htmlStr);
  15. }

  16. }

Output:
  1. <p>Java Program to remove html tags from a String</p>
  2. Java Program to remove html tags from a String

remove html code from string in java

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu