• Post Reply Bookmark Topic Watch Topic
  • New Topic

get text between two tags in a string  RSS feed

 
Janne ukko
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the .indexOf and .substring methods

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!