Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    StringTokenizer Help

    I need to read an address and phone number from a file. In the file there are three lines, each of them having something like John Doe, 123 first Street, (555) 555-5555, 123456789 on each line. I can't seem to get just the address part and return that for each line. Can someone help?

  • #2
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Here is some code I am using to recover things with token maybe this will help you.

    Code:
    try
               {
                   data = m.SeeMethod("Friends");
               }
               catch (IOException ex) {
                Logger.getLogger(Pools_and_Spas.class.getName()).log(Level.SEVERE, null, ex);
               }
               String[] msgVend = new String[data.length];
               String FriendCompany = "";
               String FriendAdd1 = "";
               String FriendAdd2 = "";
               String FriendCity = "";
               String FriendState = "";
               String FriendZip = "";
               String FriendPhone = "";
               String FriendContact = "";
               String FriendProducts = "";
    
               // loop nested to fill array of messages
               for(int i = 0; i < data.length; i++)
               {
                   String Line = data[i];
    
                   for(int j = 0; j < data.length; j++)
                   {
                        StringTokenizer st = new StringTokenizer(Line, "|");
                        FriendCompany  = st.nextToken();
                        FriendAdd1        = st.nextToken();
                        FriendAdd2        = st.nextToken();
                        FriendCity         = st.nextToken();
                        FriendState       = st.nextToken();
                        FriendZip          = st.nextToken();
                        FriendPhone      = st.nextToken();
                        FriendContact    = st.nextToken();
                        FriendProducts   = st.nextToken();
    
                   }
                   """""HERE"""""
    
         }


    Then you have all your variables set you should be able to pull what you eithier by showing from where I put """"HERE""" or by storing in another array

    Hope this helps


  •  

    Posting Permissions

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