Results 1 to 4 of 4
- 06-27-2010, 01:28 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 2
- Rep Power
- 0
Finding and storing a word from a string builder
Hi all.
Ive created a program that pulls the html from a page that I send it to, the program then stores all of this data in a string builder.
My question is how would I then go about searching this string builder for a specific set of words? When Its found this set of words I'd like to store them as a string so I can compare them to another string.
I've tried looking and playing around with the API of the stringbuilder class, but still havent managed to come up with a solution.
My idea would be to create a for loop and search through then when the string I want is found I would store that, however I just cant seem to workout how to do it.
If anyone has any ideas Id much appreciate them!
Here is my source:
Java Code:public class Checker { private URL appleTreeSeed = null; private URLConnection appleTreeSeedConnection = null; private BufferedReader appleTreeSeedData = null; private StringBuilder appleTreeSeedDataBuilder = null; private InputStreamReader appleTreeSeedFeed = null; private String nextLine; public Checker() { establishConnections(); } public void establishConnections() { //Set up the apple tree seeds url and stream the data into the buffered reader. try { appleTreeSeed = new URL("http://services.runescape.com/m=itemdb_rs/Apple_tree_seed/viewitem.ws?obj=5283"); appleTreeSeedConnection = appleTreeSeed.openConnection(); appleTreeSeedFeed = new InputStreamReader( appleTreeSeedConnection.getInputStream()); appleTreeSeedData = new BufferedReader(appleTreeSeedFeed); appleTreeSeedDataBuilder = new StringBuilder(); nextLine = appleTreeSeedData.readLine(); while (nextLine != null) { appleTreeSeedDataBuilder.append(nextLine + "\n"); nextLine = appleTreeSeedData.readLine(); } appleTreeSeedData.close(); printData(); } catch(MalformedURLException e) { e.printStackTrace(); } catch (IOException e1) { System.out.println("Error in reading data from jagex"); } } public void printData() { System.out.print(appleTreeSeedDataBuilder.toString()); }
- 06-27-2010, 01:48 PM #2
Have you read the API doc for the StringBuilder class?how would I then go about searching this string builder
What kind of method do you need that is not there?
Are there better methods in the String class? If so you could convert the StringBuilder to a String and use its methods.
- 06-27-2010, 02:02 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 2
- Rep Power
- 0
- 06-28-2010, 12:46 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,422
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Storing a string in StringTokenizer
By kgkamaraj in forum New To JavaReplies: 3Last Post: 02-12-2010, 01:58 PM -
storing a string in an array
By tiyani in forum New To JavaReplies: 3Last Post: 08-12-2009, 07:25 PM -
Find index position of every word in a String
By pentace in forum New To JavaReplies: 6Last Post: 06-28-2009, 08:26 PM -
string vs string builder??
By j2vdk in forum New To JavaReplies: 6Last Post: 09-08-2008, 09:38 AM -
Finding the exact length of a string in a JLabel (in pixels)
By Clarkey in forum Advanced JavaReplies: 2Last Post: 03-25-2008, 05:49 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks