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]
# 1
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.
hunter9000a at 2007-7-12 16:48:27 > top of Java-index,Java Essentials,Java Programming...
# 2

> 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 > top of Java-index,Java Essentials,Java Programming...
# 3
I don't think split was added until 1.4.
_helloWorld_a at 2007-7-12 16:48:27 > top of Java-index,Java Essentials,Java Programming...
# 4
> What is the best way of dividing the above String. I am using JDK1.3.Why are you kicking it old school?
Hippolytea at 2007-7-12 16:48:27 > top of Java-index,Java Essentials,Java Programming...
# 5

> > 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.

hunter9000a at 2007-7-12 16:48:27 > top of Java-index,Java Essentials,Java Programming...
# 6
> split() is my preferred method, but yes, it's not> available in 1.3.I should have read the question more carefully; my bad.
jbisha at 2007-7-12 16:48:27 > top of Java-index,Java Essentials,Java Programming...
# 7
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)) ; }
suunknowna at 2007-7-12 16:48:27 > top of Java-index,Java Essentials,Java Programming...