This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft 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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "StringUtils.substringBetween issue, please help" Watch "StringUtils.substringBetween issue, please help" New topic
Author

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) {
occurrences++;
index++;
}

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 :)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StringUtils.substringBetween issue, please help
 
Similar Threads
Struts Validation Framework Problem...........Do Help
wide navigation bar causes problems
JQuery XML parsing and HTML construction
selecting pure text in jquery
Composite Recursive List