aspose file tools*
The moose likes Beginning Java and the fly likes How to parse a string with Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to parse a string with "|" and empty strings" Watch "How to parse a string with "|" and empty strings" New topic
Author

How to parse a string with "|" and empty strings

Rajani Gummadi
Ranch Hand

Joined: Dec 17, 2010
Posts: 48
Hi All,

I'm trying to parse a String like A|B|C|D||||| as follows



My expectation is as follows

Token = A
Token = B
Token = C
Token = D
Token =
Token =


But I get only first 4, obviously the last 2 are not considered or ignored... I knew that my regular expression is wrong, but could not figure out the solution on how to have the emply strings surrounded by "|" is also retrieved..

Can some body help me in this ?


Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Use the form of "split" that takes a second int parameter; pass Integer.MAX_VALUE as the argument when you call it. The empty substrings will be returned.


[Jess in Action][AskingGoodQuestions]
Rajani Gummadi
Ranch Hand

Joined: Dec 17, 2010
Posts: 48
Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to parse a string with "|" and empty strings