Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rajani Gummadi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rajani Gummadi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic