• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StringUtils.substringBetween issue, please help

 
Gary Sheldon
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic