jhughes4
asked on
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.
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.
use split method
public static final String DELIMITER = ":";
public static final String CONTACT = ":";
String strDelimiter = (String)pRequest.getParame
String strList = (String)pRequest.getParame
StringTokenizer strTokenizer = new StringTokenizer(strList, strDelimiter);
Vector vector = new Vector(10);
while (strTokenizer.hasMoreToken
vector.add(strTokenizer.ne
}
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));
}
ASKER
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.
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
REPLACE
public static final String CONTACT = ":";
WITH
public static final String CONTACT = "Your Text Goes Here"; // Generally this should be read from the file
ASKER
Received the following error:
java:9: cannot find symbol
symbol : variable pRequest
location: class emailParse
String strDelimiter = (String)pRequest.getParame ter(DELIMI TER);
cannot find symbol
symbol : variable pRequest
location: class emailParse
String strList = (String)pRequest.getParame ter(CONTAC T );
thanks
java:9: cannot find symbol
symbol : variable pRequest
location: class emailParse
String strDelimiter = (String)pRequest.getParame
cannot find symbol
symbol : variable pRequest
location: class emailParse
String strList = (String)pRequest.getParame
thanks
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,DE LIMITER);
Vector vector = new Vector(30);
while(strTokenizer.hasMore Tokens()) {
vector.add(strTokenizer.ne xtToken(). 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));
}
}
}
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,DE
Vector vector = new Vector(30);
while(strTokenizer.hasMore
vector.add(strTokenizer.ne
}
for(int i = 1; i <= vector.size(); i++ )
{
String s = (String)vector.elementAt(i
if(s.equals(":"))
System.out.println(vector.
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.