Using indexOf to find multiple instances?

I have code that will take html code and a tagname (ex. img) and it will return the whole tag (ex. <img src="blabla.jpg">yay</img>). Problem is, I need it to return every instance of that tag. So instead of returning the first instance that it finds of <img>, it returns a String array (i guess) of every instance of an <img>...</img> tag.

publicstatic String findTag(String html, String tagname){

return html.substring(html.indexOf("<"+tagname+">"),(html.indexOf("</"+tagname+">") + tagname.length() + 3));

}

[829 byte] By [dingobiatcha] at [2007-11-26 12:58:37]
# 1
Loop through the String to find all of them.
CaptainMorgan08a at 2007-7-7 16:56:22 > top of Java-index,Java Essentials,Java Programming...
# 2

There is another indexOf method that takes a second int parameter that indicates where to start searching from. Look at the following example and see how you can modify it for your purposes.

class Indexy {

public static void main(String[] args) {

String text = "abcdeabcdabcabcde";

int location = -1;

while((location = text.indexOf("a", location + 1)) != -1) {

System.out.println(location);

}

}

}

floundera at 2007-7-7 16:56:22 > top of Java-index,Java Essentials,Java Programming...