Results 1 to 2 of 2
  1. #1
    WillBro is offline Member
    Join Date
    Apr 2014
    Rep Power

    Default Using a string tokenizer and string buffer to decode a message?

    So I have this file in which has a few sentences on a single line. What I need to be able to do is read the file and then take each word and create a token out of it. Then what it does is it selects the first letter of every 5th word, uppercase it, and then allow me to use append it via a stringbuffer object to create a word out of it.

    I know I'll need to use a string tokenizer but I'm not sure how to do so in a way that makes each word separate and how to tell it to only hit the 1st letter of every 5th word.

    Heres what I've come up with so far, but I'm currently at a loss at what to do and my textbook/documentation is just not helping.

    Java Code:
    String line; // The line we read from the file.
       char letter; // The first letter of each 5th word.
       String sw; // The completed string.
       public static void main (String [] args)throws IOException
          FileReader file = new FileReader("secret.txt");
    		BufferedReader input = new BufferedReader(file);
          line = inputFile.readLine();
          StringTokenizer st = new StringTokenizer(line);
          while (st.hasMoreTokens())
             letter = line.charAt(0);
             StringBuilder str = new Stringbuilder(letter);
             sw = str.append(letter);

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Using a string tokenizer and string buffer to decode a message?

    After you read in a line and pass it to the StringTokenizer constructor,yYou need to call a StringTokenizer method to get the next token from that line into a String. See the API doc for a short example.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Decode base64 string to an image(pdf, png, ....)
    By RohitBBorse in forum New To Java
    Replies: 0
    Last Post: 05-25-2011, 02:07 PM
  2. Need help with string tokenizer
    By ShortIt in forum New To Java
    Replies: 1
    Last Post: 02-18-2011, 08:04 PM
  3. Why we use String compare to String Buffer
    By Sharath_Forums in forum New To Java
    Replies: 1
    Last Post: 12-06-2010, 07:21 AM
  4. allowable characters from URLDecoder.decode(String
    By Nicholas Jordan in forum Networking
    Replies: 4
    Last Post: 10-18-2008, 06:46 PM
  5. Help with String Buffer
    By mathias in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 07:52 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