aspose file tools*
The moose likes Beginning Java and the fly likes Reteturning a string between a string from a html file and storing it in an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reteturning a string between a string from a html file and storing it in an array " Watch "Reteturning a string between a string from a html file and storing it in an array " New topic
Author

Reteturning a string between a string from a html file and storing it in an array

Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
Hi guys im new to Java, this being my first program. I need to extract the names of some resources from a html file and storing them in an array. Basically i need to read in the html file, find a string and store the value between the "<@dynamichtml" and "@>" parts returning the resource name.

example <@dynamichtml resource_name@> all i need is the resource_name

Once i have the name i need to repeat the process and store all the results in an array. Once this is done i then need to sort the array and print out the results.


My previous program compiled without any errors, however i've just edited the while loop and its now complaining, can anyone please help. This is really stressing me out

Kind & Greatfull Regards

S

Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
I suppose you imported all the necessary classes needed to compile the code.

Look at the way you call methods.

At line 14 for example



You call a method as if you were declaring it.
When you call a method you pass parameters to it without specifying their types



Obviously you must have declared what beg,end and line are, before.


Bye,
Nicola
Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
Hi Nicola,

Here is the complete code, apologies regarding the method, i did not mean to leave the string part inside there.
The issue im having is that the compiler wont let me use "beg" & "end" as a string type, its having trouble processing the symbols as a string i.e. beg="<@dynamichtml " and end="@>" the compiler simply says it cannot find the variable, which is why i left the code for open ideas.

regards Nick


Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
Hi Nick,
no need to apologyze really, i just wanted to be sure you imported all the classes and let you notice the way the method has to be called.

Perhaps i am not understanding your question then.
As you wrote the code, you don't specify what beg and end are. So the compiler does not find the symbols beg and end

In your last example add this code at line 19 for example



I ensure you that compiler won't complain after you told what beg and end are
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38876
    
  23
Where did you declare beg and end? You need to check about the scope of local variables and the scope of method/constructor parameters and the scope of fields.

And welcome to the Ranch
Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
Nicola Garofalo wrote:Hi Nick,
In your last example add this code at line 19 for example



I ensure you that compiler won't complain after you told what beg and end are


Hi Nicola, thats the thing when i declare them in that way i get Find.java uses unsafe or unchecked declarations and recompile with Xlint.

On Line 19 from my previous post I had a suggestion made along the lines of
ArrayList<String> results= new ArrayList<String>();

but am not sure what was ment by that as there was no comment.
could it mean ArrayList<String>arrayList=new ArrayList<String>(beg,end,line)???
This is new to me so alot of this has been trial and error.
thanks again

regards

Nick
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
Yes,
but if you notice it, your class Find.class already exists. The code is compiled.

At line 20 you are expected to specify the type of objects that your ArrayList holds.



means that you declare to the compiler that your ArrayList will hold String objects.

Modify your ArrayList declarations at line 20 as above and you are done.

One more thing
your test at line 23

is useless.

arrayList can't be null because it references an object created at line 20.
Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
Hi Nicola please ignore the previous test, i was in the process of editing whilst replying and must have got a bit over eager lol.

I've tested the code below and now get1 error located on line 20.
cannot find symbol ArrayList<java.lang.String.java etc

the location it gives is arrayList=new ArrayList, have i miss names something here, i thought an array list was declared as ArrayList, my array is called arrayList.

regards Nick






Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
Line 8 is wrong



doesn't mean anything.

You must say the compiler that you ArrayList will hold String objects. To do that write that line as follows.



Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
Nicola Garofalo wrote:Line 8 is wrong



doesn't mean anything.

You must say the compiler that you ArrayList will hold String objects. To do that write that line as follows.





Hi Nicola, compiling the code like that does work without any errors, however there is no output from the htm file its reading???
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308

No, no output at all.
What do you want to do with that newly created ArrayList?

Do you want to print it out, or put it in a file? it's up to you.

With the code posted you filled the arrayList, now do something with it, whatever you like.

Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
Nicola Garofalo wrote:
No, no output at all.
What do you want to do with that newly created ArrayList?

Do you want to print it out, or put it in a file? it's up to you.

With the code posted you filled the arrayList, now do something with it, whatever you like.



ahhh what a RETARD (slaps himself in the head), i got so caught up in getting the data into the array lol. I just want to sort it in ascending order before printing it so would it be something along the lines of arrayList.sort();
followed by a print line
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38876
    
  23
Is there a sort() method in the List interface? You may mean Collections.sort(myList);
Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
Campbell Ritchie wrote:Is there a sort() method in the List interface? You may mean Collections.sort(myList);


lol i wasn't being literal, as i mentioned previously im brand new to java it was just a sudo reference, i looked around the other day and saw something along those lines , yep thats what I was meaning to say,

thankyou tho
regards Nick
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38876
    
  23
Carefull aboutt you'r spelllings, please. Is that a "sudo" (calling the superuser in a Unix shell) reference, or a "pseudo" (unreal) reference or a "sudoku" (=Latin square) reference?
Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
lol "pseudo"
Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
Only thing is obv i need to do a simple sort and print now but im having trouble of thinking where i should put it, should I create another method and call it or is there an easier place i can assign the. Basically once the buffer has finished reading the html file id like it to arrange and print the array before it closes.
regards S
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38876
    
  23
Return the List; then you can decide whether to pass it to another method for sorting. Get your methods short. Let one method do one thing and one thing only and do it well. Try to avoid methods which try to do lots of things. So you will probably want more smaller methods.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reteturning a string between a string from a html file and storing it in an array