JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

Program: How to remove html tags from a string?


Description:

In case if a string contains html tags, then below example helps to trim the html tags from the string. The example uses regular expression to trim the html tags from the string.


Code:
package com.java2novice.string;

public class MyHtmlTagRemover {

	public static void main(String a[]){
		String text = "<B>I don't want this to be bold<\\B>";
		System.out.println(text);
        text = text.replaceAll("\\<.*?\\>", "");
        System.out.println(text);
	}
}

Example Output

<B>I don't want this to be bold<\B>
I don't want this to be bold

Other String Function Examples

Knowledge Centre
What is adapter class?
An adapter class provides the default implementation of all methods in an event listener interface. Adapter classes are very useful when you want to process only few of the events that are handled by a particular event listener interface. You can define a new class by extending one of the adapter classes and implement only those events relevant to you.
Famous Quotations
The very best thing you can do for the whole world is to make the most of yourself.
-- Wallace Wattles

About Author

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2017 by Nataraja Gootooru. All Rights Reserved.