File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 24166
    
  30

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
 
Similar Threads
OO Parsers
Parsing
Doubt in String formatting
Tokenising using String.split().
looking for java parasers for parsing string expressions