String Tokenizer

hi
guys
what i want to do is to transfer  contents of file
which is in the formate
aaa:@:xxx:yyy
bbb:@:zzz:1.2.3.4:1.2.3.4-3.5.6.4
ccc:@:hhh:1.2.3.4:1.2.3.4-3.5.6.4:bullseye
etc
also i have to do some validations on individual tokens
like if toiken is ip address as shown
then get name of server append it to buffer
that's ok

so what i am doing is using a stream tokenizer
but the problem is when
i say
while(tokenizer.hasMoreTokens())
{
      Buffer.append(tokenizer.nextToken())
      name = tokenizer.nextToken()
      //validations like this
      if(name.equals("Amit"))
      {
            Buffer.append(name,"BE(ELECTRONICS)");
      }
      Buffer.append(tokenizer.nextToken());
      Buffer.append(tokenizer.nextToken());
}
what happens is for the first line  there is no ip address
hense while loop can't get terminated it gives exception
as no such element exists
what i need is that  loop shuld be terminated if there r no tokens
can any one help me
Argent
---Amit
amitdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

comermCommented:
Since the format of each line is variable, you need to model this as a state machine, e.g.

int state = 1;
while (tokenizer.hasMoreTokens())
{
   switch(state)
   {
      case 1:
         // we are expecting an "aaa"
         // type token.
         // if we get it, process it
         // and set state to 2...
         // if we don't get it,
         // set state equal to
         // something else...
         break;
      case 2:
         // etc.
         break;
      // etc
   }
}

When doing something like this, you need to map out your process using a state diagram. (BTW, there are better/cleaner ways to build a state machine, but the above is clear and easy to understand...)
0
amitdAuthor Commented:
this doesn'twork
0
rjackmanCommented:
hi
seems that
the problem lies with the .nextToken()
so why don't u retrieve tokens in the
vector
as
while(tokens.hasMOreElements())
{
  Vector V = token.NextToken()

}
then use it for validations
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amitdAuthor Commented:
thanx it works
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.