Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > StringTokenizer help

Reply
Thread Tools

StringTokenizer help

 
 
ARMANDO PADILLA
Guest
Posts: n/a
 
      07-04-2003
Hello Everyone I have a quick and simple problem that i cant seem to get
around. Im reading a file and seperating the fields from the file via the
delimeter ",". The problem arises when the nextToken() encounteres a blank
field. Is there a way to go around it and have the process ignor the null
field value?

For example:

String: Armando, padilla, 0, 12, 3421, hello there
Another, Name, , 32142, 1, hello

The first line will parse fine but the second will issue out an error.

Thanks for the help.

--
Armando P.
Computer Science/Economics, Cailifornia State University Los Angeles
http://www.armando.ws


 
Reply With Quote
 
 
 
 
Russell Hanneken
Guest
Posts: n/a
 
      07-04-2003
"ARMANDO PADILLA" <(E-Mail Removed)> wrote in message
news:YR7Na.645$(E-Mail Removed). ..
> I have a quick and simple problem that i cant seem to get around. Im
> reading a file and seperating the fields from the file via the delimeter
> ",". The problem arises when the nextToken() encounteres a blank field.
> Is there a way to go around it and have the process ignor the null field
> value?
>
> For example:
>
> String: Armando, padilla, 0, 12, 3421, hello there
> Another, Name, , 32142, 1, hello
>
> The first line will parse fine but the second will issue out an error.


I think we need more information. If the delimiter string is ",", then the
second line's third token will be a single space. In what way is this
causing you a problem? Are you getting an exception because you're trying
to convert the space to an int? What do you normally do with the third
token on a line, and what do you want to happen in this special case?

It might help if you illustrate your problem with a small, stripped-down
version of your code.

--
Russell Hanneken
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
 
Jacob
Guest
Posts: n/a
 
      07-04-2003
ARMANDO PADILLA wrote:
> Hello Everyone I have a quick and simple problem that i cant seem to get
> around. Im reading a file and seperating the fields from the file via the
> delimeter ",". The problem arises when the nextToken() encounteres a blank
> field. Is there a way to go around it and have the process ignor the null
> field value?
>
> For example:
>
> String: Armando, padilla, 0, 12, 3421, hello there
> Another, Name, , 32142, 1, hello
>
> The first line will parse fine but the second will issue out an error.


StringTokenizer *do* ignore empty fields, but
in your case it is not empty: A " " is returned.

Actually it is rather annoying that null is not
returned in the case of subsequent delimiters,
at least optionally:
a,,b,,c should give "a", null, "b", null, "c".
As it is now you'll have to ask for the delimiters
to be returned as well and figure this out
manually.


 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      07-04-2003
Jacob wrote:
> StringTokenizer *do* ignore empty fields, but
> in your case it is not empty: A " " is returned.
>
> Actually it is rather annoying that null is not
> returned in the case of subsequent delimiters,
> at least optionally:
> a,,b,,c should give "a", null, "b", null, "c".


I'm going into picky mode here, but this is a real pain when it's done
wrong. I agree that StringTokenizer should optionally indicate empty
fields... but null is NOT the right return value. There is a big
difference between null and the empty string (""). The empty field
should be indicated by an empty string, not a null. When someone isn't
thinking and gets this wrong, it just becomes a constant pain in the
side of people trying to use the poorly designed API.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with java StringTokenizer ronron10 Java 0 12-18-2008 02:54 AM
need help with StringTokenizer ros Java 2 05-06-2007 08:28 AM
StringTokenizer Question? Jim Crowell Java 9 08-23-2003 06:28 PM
Read data with delimater using stringtokenizer Liang Yew Java 3 07-21-2003 07:10 AM
Re: StringTokenizer Help Phil Hanna Java 0 06-30-2003 11:57 PM



Advertisments