Simple question

Can someone provide some sample code on how I can parse the following message in JDK 1.4?

User name : Mike User email : someemail.com User phone :      719443453 User address : some address User city :      LA

I want the result to be:

Mike
someemail.com
719443453
some address
LA

thanks in advance.
jhughes4Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Manikandan ThiagarajanSenior consultantCommented:
use split method
0
geekprogCommented:

public static final String DELIMITER =  ":";
public static final String CONTACT =  ":";

String strDelimiter = (String)pRequest.getParameter(DELIMITER);
String strList = (String)pRequest.getParameter(CONTACT );


      StringTokenizer strTokenizer = new StringTokenizer(strList, strDelimiter);
      Vector vector = new Vector(10);

      while (strTokenizer.hasMoreTokens()) {
            vector.add(strTokenizer.nextToken().trim());
      }

        for(int i = 1; i <= vector.size(); i = i+2 )        // Here i am incrementing +2, to display only the Values you said
        {
               System.out.println( vector.elementAt(i));
        }
0
jhughes4Author Commented:
Thanks for your response, but I haven't coded in Java in a long time & I don't have time to go through some trial and error.  I have a Siebel developer who needs a sample Java code that demonstrates how Java can parse a message so that he can replicate that feature within Siebel.  So can you provide a sample?  Thanks again.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

geekprogCommented:
small correction in my above code

REPLACE

public static final String CONTACT =  ":";

WITH

public static final String CONTACT =  "Your Text Goes Here";   // Generally this should be read from the file


0
jhughes4Author Commented:
Received the following error:
java:9: cannot find symbol
symbol  : variable pRequest
location: class emailParse
String strDelimiter = (String)pRequest.getParameter(DELIMITER);
cannot find symbol
symbol  : variable pRequest
location: class emailParse
String strList = (String)pRequest.getParameter(CONTACT );

thanks
0
geekprogCommented:
That was basically a pseudo code, anyway below is the complete code that you can run

import java.lang.*;
import java.util.*;

public class Sample
{
      public static final String DELIMITER =  " ";
      public static final String CONTACT =  "User name : Mike User email : someemail.com User phone : 719443453 User address : some address User city : LA";

      public static void main(String[] args)
      {
            StringTokenizer strTokenizer = new StringTokenizer(CONTACT,DELIMITER);
            Vector vector = new Vector(30);

            while(strTokenizer.hasMoreTokens()) {
                  vector.add(strTokenizer.nextToken().trim());
          }
      
        for(int i = 1; i <= vector.size(); i++ )
        {
                  String s = (String)vector.elementAt(i-1);
                  if(s.equals(":"))
                        System.out.println(vector.elementAt(i));
        }
      }
}
0
Manikandan ThiagarajanSenior consultantCommented:
check this one


public class split1 {
      
      public static void main(String s[])
      
      
      {
      
      
String str ="      User name : Mike User email : someemail.com User phone :     719443453 User address : some address User city :     LA";

String[] token1 = new String[10];



String [] tokens = str.split("User");


for (int i = 0; i < tokens.length; i++)
{
      tokens[i].trim();
       token1 =  tokens[i].split(":");
 // System.out.println(tokens[i]);


try
{
      System.out.println(token1[1].trim());
}

catch(Exception e)
{
      
}
      

      
}

      }
}
      
      

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.