Results 1 to 4 of 4
  1. #1
    ao241 is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default 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());
            
            
            
            
            
            
         }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    how would I then go about searching this string builder
    Have you read the API doc for the StringBuilder class?
    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.

  3. #3
    ao241 is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Have you read the API doc for the StringBuilder class?
    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.
    Thanks,

    Ive now worked out how to actualy find the correct text, using indexOf Il now work on storing the data from that string, once again many thanks!

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,340
    Blog Entries
    7
    Rep Power
    20

    Default

    Oh dear, one of the posters has gone complely bonkers; is there a medical doctor in the audience? Or a butcher ...

    kind regards,

    Jos

Similar Threads

  1. Storing a string in StringTokenizer
    By kgkamaraj in forum New To Java
    Replies: 3
    Last Post: 02-12-2010, 01:58 PM
  2. storing a string in an array
    By tiyani in forum New To Java
    Replies: 3
    Last Post: 08-12-2009, 07:25 PM
  3. Find index position of every word in a String
    By pentace in forum New To Java
    Replies: 6
    Last Post: 06-28-2009, 08:26 PM
  4. string vs string builder??
    By j2vdk in forum New To Java
    Replies: 6
    Last Post: 09-08-2008, 09:38 AM
  5. Replies: 2
    Last Post: 03-25-2008, 05:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •