开发者

String Tokenizer issue

AM using string tokenizer to delimit th开发者_运维百科e string response by ^

12/30/2011 12:00:00 AM^President^^^159^True^True^True^True^True^False^False^True^True^3/18/2011 12:00:00 AM^True^Jujama, Inc.^^^^True^True

but the problem is when ^ delimiter consecutively its skipping that one and adding in to array. But i want to add space if two ^delimiters comes.

How to do that?

My code is:

 StringTokenizer tokens = new StringTokenizer(partId, "^");

              while(tokens.hasMoreTokens()){

                 String value=tokens.nextToken();
                 userValues.add(value);
                 System.out.println("..."+value);

              }   


User string.split("^") instead. Split receives regex, so you can do almost what you want within one line.


Check out StringUtils from Apache:

http://commons.apache.org/lang/api-2.3/org/apache/commons/lang/StringUtils.html#splitPreserveAllTokens(java.lang.String, char)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜