Dividing data
Hi,
I am getting data in the following format
history=This is test2/#/cust_id=12345/#/cust_name=TEST/#/
I need to divide the above string and get the value ( for example: "This is test2" ) and add these values to a vector.
For Ex:
vector.add("This is test2");
vector.add(12345);
vector.add("TEST");
What is the best way of dividing the above String. I am using JDK1.3.
Thanks in advance.
[448 byte] By [
suunknowna] at [2007-11-27 6:04:24]

Use a StringTokenizer with a delimiter of "/#/" to get the "key=value" pairs. Then use a StringTokenizer on each pair with a delimiter of "=", read the second token, and add that to the List.
> Use a StringTokenizer with a delimiter of "/#/" to
> get the "key=value" pairs. Then use a StringTokenizer
> on each pair with a delimiter of "=", read the second
> token, and add that to the List.
Or String.split()
public String[] split(String regex)
Take note that the "delimiter" passed is actually a regular expression.
Message was edited by:
jbish
jbisha at 2007-7-12 16:48:27 >

> > Use a StringTokenizer with a delimiter of "/#/" to
> > get the "key=value" pairs. Then use a
> StringTokenizer
> > on each pair with a delimiter of "=", read the
> second
> > token, and add that to the List.
>
> Or String.split()
>
> public String[] split(String regex)
>
> Take note that the "delimiter" passed is actually a
> regular expression.
>
> Message was edited by:
> jbish
split() is my preferred method, but yes, it's not available in 1.3.
Thanks everyone for your help.I used StringTokenizer and substring/indexof to do thisStringTokenizer st = new StringTokenizer(str2, "/#/");while (st .hasMoreTokens()) { String tok = st.nextToken();vec.add(tok.substring(tok.indexOf("=")+1)) ; }