Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A recursive method!!

 
Arihant
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Arihant
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Thanks,
Cindy
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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">
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so it's a little bit more complicated. But I still wouldn't think of trying to solve the problem with recursion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic