Compare a line of ArrayList with a string
in
Programming Questions
•
2 years ago
Hi, I'm trying to get the meteorologic status of the day into processing analysing the html code on a website.
The thing is, I got the html code into an array of strings type into processing, that was easy, did some search and got it together, but I can't figure out how to compare a string with one of the lines of the array.
I tried this:
- String lines[] = loadStrings("http://www.meteo.pt/pt/html_prev.jsp");
- String detect = "<td rowspan=\"2\">Lisboa</td>";
- char cline, cdetect;
- for (int i=0; i < lines.length; i++) {
- for (int n=0; n < 24 /*lines[i].charAt(n) != "\n"*/; n++)
- {
- cline = lines[i].charAt(n);
- cdetect = detect.charAt(n);
- if (lines[i] == null)
- break;
- println(n);
- if (cline != cdetect)
- break;
- else if (cline == cdetect && n == 23)
- println("Event detected on line " +i);
- }
- }
But it gave me a "StringIndexOutOfBoundsException: String index out of range:0" on line 9.
Then I tried this:
- String lines[] = loadStrings("http://www.meteo.pt/pt/html_prev.jsp");
- String detect = "<td rowspan=\"2\">Lisboa</td>";
- char cline, cdetect;
- for (int i=0; i < lines.length; i++) {
- for (int n=0; n < 24 /*lines[i].charAt(n) != "\n"*/; n++)
- {
- try {
- cline = lines[i].charAt(n);
- cdetect = detect.charAt(n);
- }
- catch (IOException e) {
- lines[i] = null;
- }
- if (lines[i] == null)
- break;
- try {
- cline = lines[i].charAt(n);
- cdetect = detect.charAt(n);
- }
- catch (IOException e) {
- }
- println(n);
- if (cline != cdetect)
- break;
- else if (cline == cdetect && n == 23)
- println("Event detected on line " +i);
- }
- }
and it gave me "Unreachable block for IOException. This exception is never thrown from the try statement body" on line 13, but the syntax for the try statement is like this in the reference, what am I doing wrong?
Thanks
1