• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String tokenizer

 
Kalpesh Soni
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

output
------
C:\jdk\bin\java.exe TokenTest
Working Directory - D:\ksoni\javaTests\
Class Path - .;c:\jdk\lib;c:\j2sdkee1.3\lib\j2ee.jar;c:\KawaEnt5.0\kawaclasses.zip;c:\jdk\lib\tools.jar;c:\jdk\jre\lib\rt.jar;c:\jdk\jre\lib\i18n.jar
1[1003]
2[$]
3[$]
4[03]
5[$]
6[$]
7[$]
8[$]
9[suggestion1]

1[1003]
2[03]
3[suggestion1]
Process Exit...
--------
question
--------
how do i get an array of tokens ?
i do not want the $ sign
the token may not be there !in that case array element should be null
and see the delim "$a" , it seems a is ignored !
what if i have delim of two chars or more ??
--kalpesh
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kalpesh,
In your first example the letter a is not being ignored. You don't have any 'a' characters in your original string (temp). The characters inside the delimiter string are considered separately and not in a group (i.e., treated as an array of chars instead of string).
StringTokenizer has not been implemented to return empty tokens. If you require that then you must write your own tokenizer that does that.
If you want an array of tokens you can just do the following:

Regards,
Manfred.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic