<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<font face="serif">Alright -- I am EXCITED that some of you are
actually working ahead on the weather data program. I am now
getting questions like "how can I get the data once I read the
file" or "can I do it this way"...<br>
<br>
Please understand, there is no defined method for extracting the
information. Here is, however, a method that should work.
Let's say that we are trying to extract the information out of the
station.txt file. You might have all of the information in a
String variable called "line". You also know that the first
piece of information in the file is the station number and that
the file is delimited by "|" marks. This could work...<br>
<br>
</font><tt>String stationID =
line.substring(0,line.indexOf("|")).trim();</tt><font face="serif"><br>
<br>
<br>
</font>Now, to get over to the state info I need to read past
several of those "|" delimiters and then extract the info. The
following should work...<br>
<br>
<tt>boolean found = false;<br>
</tt><tt>int location = 0;</tt><tt><br>
</tt><tt> <br>
index = 0;<br>
</tt><tt>int numberFound=0;</tt><tt><br>
</tt><tt>while ( !found && index < line.length() ) {</tt><tt><br>
</tt><tt> if ( line.charAt(index) == '|' ) numberFound++;</tt><tt><br>
</tt><tt> if ( numberFound == 7 ) {</tt><tt><br>
</tt><tt> location = index;</tt><tt><br>
</tt><tt> found = true;</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> index++;</tt><br>
<tt>}<br>
</tt><tt>String stationState =
line.substring(location+1,line.indexOf("|",location+1));</tt><tt><br>
</tt><br>
<br>
Take a look at the string API to see what I am doing on that last
line. To see if your code is working, print out the stationID and
the state.<br>
<br>
<br>
<pre class="moz-signature" cols="72">--
Andrew J. Pounds, Ph.D. (<a class="moz-txt-link-abbreviated" href="mailto:pounds_aj@mercer.edu">pounds_aj@mercer.edu</a>)
Professor of Chemistry and Computer Science
Mercer University, Macon, GA 31207 (478) 301-5627
<a class="moz-txt-link-freetext" href="http://faculty.mercer.edu/pounds_aj">http://faculty.mercer.edu/pounds_aj</a>
</pre>
</body>
</html>