Java Reference
In-Depth Information
// convert everything to lower case
String searchStr = str.toLowerCase();
token1 = token1.toLowerCase();
token2 = token2.toLowerCase();
// now search
location1 = location2 = 0;
do
{
if( location1>0 )
location1++;
location1 = searchStr.indexOf(token1, location1 );
if (location1 == -1)
return null;
count--;
} while (count > 0);
// return the result from the original string that has mixed
// case
location2 = str.indexOf(token2, location1
+ token1.length() + 1);
if (location2 == -1)
return null;
return str.substring(location1 + token1.length(), location2);
}
/**
* This method will download data from the specified state.
* This data will come in as a partial HTML document,
* the necessary data will be extracted from there.
* @param state The state you want to download (i.e. Missouri).
* @throws IOException Thrown if a communication error occurs.
*/
public void process(String state) throws IOException
{
URL url = new URL(
"http://www.httprecipes.com/1/10/statehtml.php?state="+state);
String buffer = downloadPage(url,10000);
String name = this.extractNoCase(buffer,"<h1>", "</h1>", 0);
String capital = this.extractNoCase(buffer,
"Capital:<b></td><td>", "</td>", 0);
Search WWH ::




Custom Search