[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Simple question

Posted on 2006-03-27
7
Medium Priority
?
279 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:jhughes4
  • 3
  • 2
  • 2
7 Comments
 
LVL 9

Expert Comment

by:Manikandan Thiagarajan
ID: 16306442
use split method
0
 
LVL 1

Expert Comment

by:geekprog
ID: 16306457

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
 

Author Comment

by:jhughes4
ID: 16306459
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:geekprog
ID: 16306466
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
 

Author Comment

by:jhughes4
ID: 16306481
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
 
LVL 1

Expert Comment

by:geekprog
ID: 16306676
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
 
LVL 9

Accepted Solution

by:
Manikandan Thiagarajan earned 2000 total points
ID: 16306707
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month19 days, 23 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question