• Post Reply Bookmark Topic Watch Topic
  • New Topic

testing for null spaces  RSS feed

 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • 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("");
}
 
William Barnes
Ranch Hand
Posts: 1049
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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 ]
 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!