Java Reference
In-Depth Information
System.out.println(result.toString());
}
/**
* This method is very useful for grabbing information from a
* HTML page.
*
* @param url The URL to download.
* @param token1 The text, or tag, that comes before the
* desired text.
* @param token2 The text, or tag, that comes after the
* desired text.
* @param count Which occurrence of token1 to use, 1 for
* the first.
* @return The contents of the URL that was downloaded.
* @throws IOException Thrown if any sort of error occurs.
*/
public String extractNoCase(String str, String token1,
String token2, int count)
{
int location1, location2;
// convert everything to lower case
String searchStr = str.toLowerCase();
token1 = token1.toLowerCase();
token2 = token2.toLowerCase();
// now search
location1 = location2 = 0;
do
{
location1 = searchStr.indexOf(token1, location1 + 1);
if (location1 == -1)
return null;
count--;
} while (count > 0);
location1 += token1.length();
// return the result from the original string that has mixed
// case
location2 = str.indexOf(token2, location1 + 1);
if (location2 == -1)
return null;
Search WWH ::




Custom Search