Try using either String.indexOf() or a regular expression to match the location of <A href=.
Get the index and add the length of <A href= to it. You not have a start index.
From that start index, find the first occurrence of "> using the indexOf() method or a regular expression.
You now have start and finish indices. Use those to obtain a substring.
Put that substring into an ArrayList<URL> or an ArrayList<String>
Repeat until you reach the end of the String.
I think that will probably work. Try it.
Joined: Mar 07, 2008
Thanks for your suggestion, I tried according but I got out of bound exception
int i=line.indexOf("<A href="); out.println(i); int len = i+"<A href=".length(); i = line.indexOf(">",len+1); out.println(i); line=line.substring(len+1,i+1); out.println(line); Please let me know if I commit any mistake in the code.
The exception will tell you which line of your code it happened on. Look at the documentation for the methods on that line and see what could cause the exception.
Joined: Oct 13, 2005
Look closely through the details of the substring() method. You may be getting problems because of the +1. In case you are getting lines ending with /a> rather than . . .>link text</a> you might try getting the index of /a> as well, and using that if it is less than the index of >. There is a simple method in the Math class which can do that for you.