Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to remove html tags from string java

  • 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 : hello
  • 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 = "

    Java Program to remove Html Tags from a String

    ";
  12.         System.out.println(htmlStr);
  13.         htmlStr = htmlStr.replaceAll("\\<.>", "");
  14.         System.out.println(htmlStr);
  15. }

  16. }

Output:
  1. Java Program to Remove Html tags from a String

  2. Java Program to remove html tags from a String




This post first appeared on Java Tutorial - InstanceOfJava, please read the originial post: here

Share the post

How to remove html tags from string java

×

Subscribe to Java Tutorial - Instanceofjava

Get updates delivered right to your inbox!

Thank you for your subscription

×