File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes A recursive method!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "A recursive method!!" Watch "A recursive method!!" New topic

A recursive method!!


Joined: Oct 02, 2002
Posts: 1
Can somebody please help me in writing a recursive method to remove all the HTML tags from a given String. (Note that an HTML tag begins with < and ends with >.)
thanks and regards,
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Read this article on Regular Expressions. They can help you identify when you have bumped into a pattern matching an html tag.
oh - and Arihant,
Please change your name to be compliant with JavaRanch's naming policy.
Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
You can change your name: here.

"JavaRanch, where the deer and the Certified play" - David O'Meara
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Is there some special reason you want to do this with recursion (besides it being homework I mean). Just stop down the string, if you are inside less-than and greater-than don't copy that out.

Please ignore post, I have no idea what I am talking about.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
It's a little more complicated than that, since you can legally have "<" and ">" characters inside a quoted attribute value, for example:
<input name="a<b">
<input name="a>b">

Ron Newman - SCJP 1.2 (100%, 7 August 2002)
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Ok, so it's a little bit more complicated. But I still wouldn't think of trying to solve the problem with recursion.
I agree. Here's the link:
subject: A recursive method!!
jQuery in Action, 3rd edition