Hi I need to tokenize a string with ',' as delimiter. for example in the string below: Sreeni, san, 12345, , #44 XYZ street,,234567 Here I need to tokenize with comma as delimiter. The problem is with the value is not specified and instead when ,, is specified. The StringTokenizer skips this as a value, whereas , , is returned as blank. How do I overcome this problem, when ,, is specified. Note: comma character in the above string is not a value. Thanks Sreeni
aminur rashid
Ranch Hand
Joined: Sep 21, 2001
Posts: 79
posted
0
Hi sreeni. I have tried to solve ur problem.You can have other logic for this also.What i have done in this function is that i have used a temproryTokenizer.From this temproryTokeniser i have eliminated the tokens with values" " and null Then i have made the finalToknizer
cheers
Regards<br />Aminur
sreeni san
Ranch Hand
Joined: Aug 14, 2001
Posts: 39
posted
0
HI Thanks for the reply. The problem I have is that I need to retrieve token when the value is ,, . The StringTokenizer just skips this. I'll try to modify my example: I have data pertaining to a user for the fields below: fName, lname, userId, address1, address2,city, phone The corresponding values for the above fields are Sreeni, san, 12345, , #44 XYZ street,,234567 Now I tokenize the entire String and assign values to respective variables. While doing so I have encountered problems like for example: The value for fName, lname, userId, address1, address2 are returned correctly as tokens. The problem here is with city as the value ",," is skipped and 234567 is returned as next token immediately after address2. In case of address1 ", ," is value is returned as blank, which is fine for me. Kindly suggest me a suitable solution.
thanks Sreeni
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
What if you replace ,, with , , or ,"", or ,null, before you use the StringTokenizer?
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
aminur rashid
Ranch Hand
Joined: Sep 21, 2001
Posts: 79
posted
0
Hello the problem with that is ''while ' ' makes a string with a space character. You can try one thing .Use the constructer
It will return values the delimiter , after every string.Write a method to create a null or "" string if u get two , without getting any values.Hope this will help
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
posted
0
If you're using SDK 1.4, you can handle this easily using the String class' split() method. Otherwise, here's a class I wrote some time ago to solve this problem: