This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes get text between two tags in a string Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "get text between two tags in a string" Watch "get text between two tags in a string" New topic
Author

get text between two tags in a string

Janne ukko
Greenhorn

Joined: Nov 25, 2004
Posts: 10
Hello!

if i have a String that look like this

String s="[tag]jajasljalfjasljldjdasld[/tag][tag12]afalejljldjlefe[/tag12]";

how can i do to only get the text that is inside the [tag][/tag]

regards
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
Look at the .indexOf and .substring methods



Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Well, we're in advanced so I'll bring up Regular Expressions. You can compile a Pattern object then use its methods to get a Matcher for your input string and use find() and group() methods to get what was found. I hope that used just enough of the right words to get you started in the JavaDoc. Holler if you'd like examples. I have something almost exactly like what you need.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: get text between two tags in a string
 
Similar Threads
problem with html:text prpperty value=bean:write
RTExpr Attribute Value Given in Tag Body
<bean:message> and jquery
How to get Image from request
about logic:iterate