• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

testing for null spaces

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have this code which is below but it will not test to see if between 2 delimeters is a empty string or not.
all it does is to test the first and last tokens.
how do i test to see if there is a string between 2 delimeters or not and if there is not i would like it to go into a vector.
but i still want the code below
any ideas please
thanks
ben
while (s.hasMoreTokens()) {
token = s.nextToken();
if (lastToken){
if (token.equals(",")) {
v.add("");
}
lastToken = false;
}
if (! token.equals(",")) {
v.add(token);
}
}
if (token.equals(",")) {
v.add("");
}
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know that I am confused by your question, but I think you might confused about what the StringTokenizer class does for you.
By default the delimeter is space. Did you use the default? Your code looks like you are trying to test every character. Your tokens are most likely not characters.
Write a loop which just prints out the tokens, so you can understand what the code is actually doing.
Please use *code* tags when posting code.

[ November 27, 2002: Message edited by: William Barnes ]
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ben,
You may be confusing tokenising with parsing. If your intent is to parse a string, you will probably want to read up on the new java.util.regex.* classes, and specifically the Pattern class.
In Perl we do similar things using regex's in splits.
PCS
[ November 27, 2002: Message edited by: Philip Shanks ]
reply
    Bookmark Topic Watch Topic
  • New Topic