wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Isolating one line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Isolating one line" Watch "Isolating one line" New topic
Author

Isolating one line

Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Hello everybody, i am new here, and i have a little problem
I have text:
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../../../layout2.css" type="text/css" rel="stylesheet">
<title>Народна банка СрбиŃ?е</title>
</head>
<body>
<table width="190" cellspacing="2" cellpadding="2" border="0">
<tr>
<td class="patern"><a target="_blank" href="/export/internet/cirilica/40/40_5/indikativni_kurs.html"><font color="white">ĐšŃ?Ń€Ń? динара >>></font></a></td>
</tr>
<tr>
<td class="center">Званични Ń?редњи ĐşŃ?Ń€Ń? Đ·Đ° Đ´Đ°Đ˝ 06.02.2009: 

<b>91.9553</b></td>
</tr>
</table>
</body>
</html>

which i get by reading from http site!
I have to isolate 16th line (<b>91.9553</b></td>) then convert it to integer,remove chars just leave number, which i think i now how to do, but im not sure ... But i cant get rid of the rest of the text!
Regards
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

how are your reading this? is it in a file?

Assuming so, what is special about this line? is it always, say, the 17th line?

use a counter and you'll know when your on that line.

is it always after the only line with 'class' in it? if so, keep reading and searching for that line, then read one more.

is it the only line with a number in it?

My point is that it's kind of hard to answer your question. We don't have enough info. Can you elaborate more on what the conditions are for which lines you need to grab?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
It is not a file! I read http page with URL class and BufferedReader, so its just html and javascript here. But i can save it as a file. I cant specifie anywhere how many lines or witch i need to read. I can just say, like, input.ReadLine() not input.ReadLine(16); And yes its always the same line, i am making a programme that every time it starts, download that number from the same page(page is refreshed every day) and use it ...
edit: I can also ask like this: How can i get this text, string(<b>91.9553</b></td> )from the whole text! (sorry for my bad english)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40

I can just say, like, input.ReadLine() not input.ReadLine(16); And yes its always the same line, i am making a programme that every time it starts, download that number from the same page(page is refreshed every day) and use it ...


Why can't you just call readline() 16 times in a loop? And ignore the first 15 lines?

edit: I can also ask like this: How can i get this text, string(<b>91.9553</b></td> )from the whole text! (sorry for my bad english)


As you already said... read it one line at a time til you get the line you want.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Yes, i did it with for loop i<16 and then ignoring first 14 lines! Thank you
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528


If you want something you never had do something which you had never done
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37951
    
  22
You can find the 1st line beginning with "<b>" using the BufferedReader#readLine() method, and the String#beginsWith (or maybe String#startsWith; I can't remember which is correct) inside the () of a while loop. The body of the while can be empty, then the next line after the end of the while is the line you are looking for.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37951
    
  22
RaviNada Kiran wrote:
What problem are you having with this question?
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Campbell Ritchie wrote:
RaviNada Kiran wrote:
What problem are you having with this question?



so you encourage this type of coding pratice ?? strange , thats my problem and waht's yours ???
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40

so you encourage this type of coding pratice ?? strange , thats my problem and waht's yours ???


Please elaborate. We can't read your mind.

And I don't think Campbell has a issue with this topic -- he is just making sure that everyone not be afraid to ask questions when they obviously want to. So, please elaborate... we can't have any discussions about your issue unless you start it..

Henry
Ivan Kesic
Ranch Hand

Joined: Feb 05, 2009
Posts: 68
Campbell Ritchie wrote:You can find the 1st line beginning with "<b>" using the BufferedReader#readLine() method, and the String#beginsWith (or maybe String#startsWith; I can't remember which is correct) inside the () of a while loop. The body of the while can be empty, then the next line after the end of the while is the line you are looking for.

This idea is i think much better then for loop
I have one more question. I am reading a line from URL with URL class and BufferedReader... Can sometimes happen that it cant read the whole page source, and just remove one part? It happened to me, and i don't know why. I go for page source via IE and see whole code, but when my programme reads it, one part is missing?!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Isolating one line
 
Similar Threads
When I validate my code I hit this problem...
GET html contents from a web server
Array Index Out Of Bounds
using Multiple submit buttons.
When I validate my code I hit this problem...