This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes StringUtils.substringBetween issue, please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "StringUtils.substringBetween issue, please help" Watch "StringUtils.substringBetween issue, please help" New topic

StringUtils.substringBetween issue, please help

Gary Sheldon
Ranch Hand

Joined: Nov 21, 2011
Posts: 44
I have the following code which parses an XML feed, strips out the <ul> tags for each row of data. I am then left with in some cases multiple <li> tags within a single string each of which contain an <a> tag. The code then proceeds to get the value between each <a> tag located within each <li>. However the StringUtils.substringBetween function is only dealing with the first <a> tag and disregarding any other <a> tags found in the same string. The code to display the number of occurences is correct, but I am at a loss of why the stringBetween function is only dealing with one <a> tag per row of data instead of the possibility of multiple <a> tags within a sign string:

String suitableStrip = Suitable.item(i).getFirstChild().getNodeValue().trim();
suitableStrip = utils.replace(suitableStrip, "<ul>", "");
suitableStrip = utils.replace(suitableStrip, "</ul>", "");
String modelStrip = StringUtils.substringBetween(suitableStrip, "\">", "<");

int occurrences = 0;
int index = 0;
while (index < suitableStrip.length() && (index = suitableStrip.indexOf("<li>", index)) >= 0) {

Any help would be much appreciated :-)
Gary Sheldon
Ranch Hand

Joined: Nov 21, 2011
Posts: 44
Oops, didnt realise there was a substringsBetween option, simply modified modelStrip as follows:

String modelStrip[] = StringUtils.substringsBetween(suitableStrip, "\">", "<");

Hope this proves useful to someone else :)
subject: StringUtils.substringBetween issue, please help
Similar Threads
JQuery XML parsing and HTML construction
Composite Recursive List
selecting pure text in jquery
Struts Validation Framework Problem...........Do Help
wide navigation bar causes problems