File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Isolating one line

 
Ivan Kesic
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Ivan Kesic
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ivan Kesic
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i did it with for loop i<16 and then ignoring first 14 lines! Thank you
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RaviNada Kiran wrote:
What problem are you having with this question?
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic