Hi I am using StringTokenizer class to parse a string but its missing some empty tokens. Ex = "ramesh,krishns,kishore,,venu,raja" its giving the output as ramesh krishns kishorevenu raja i wena to trap the ,, also how to do Regards Ramesh R G V S
Yes, you are correct. Consecutive delimiters appear to be thrown away. Perhaps using the StringTokenizer constructor which has three arguments, the last being a returnDelimsboolean will help you solve your problem. Setting returnDelims to true will return the delimiter strings (commas in your case) as well as the token strings. You can the detect the occurence of two consecutive tokens with some extra code. -Barry [ December 26, 2002: Message edited by: Barry Gaunt ]
Thanks to Jim Yingst, from another post, I see that there is a method of String added to Java 1.4 which you can use. String split(String regexp); It works with a string like "A,B,,,E". However, if you have "A,B,C,," you will have to look after the last trailing empty string yourself it seems.
Hi Ramesh, To get trap the delimeters also use the constructor option for StringTokenizer as
StringTokenizer(String str, String delim, boolean true) if we use this constructor for StringTokenizer then the delimeter character are also returned as tokens. And if the flag is false, then the delimeter chatarcter are skipped and delimeter is only used as delimeters between the tokens. Default flag is false. Regards, Vishwanath
Originally posted by Ramesh R G V S: Hi I am using StringTokenizer class to parse a string but its missing some empty tokens. Ex = "ramesh,krishns,kishore,,venu,raja" its giving the output as ramesh krishns kishorevenu raja i wena to trap the ,, also how to do Regards Ramesh R G V S
jay, I wouldn't expect it to. The argument to split is a String representing a regular expression. If instead of using "." as an argument, you use "\\." you will find that it works. You must use two backslashes. Read the API and learn about regular expressions. -Barry [ December 30, 2002: Message edited by: Barry Gaunt ]