File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes split by pipe in a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "split by pipe in a string" Watch "split by pipe in a string" New topic

split by pipe in a string

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 441

I need split by "|" when I reading from a file.

I am using the next code

In my file I have


I get the next out put "" "D""o""d""1""|".............

But I want an output like "Dod1" "2" "3"

Any idea please?


Winston Gutkowski

Joined: Mar 17, 2011
Posts: 8626

Angus Ferguson wrote:Any idea please?



Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Matthew Brown

Joined: Apr 06, 2010
Posts: 4518

And if you want to know why your original didn't work, have a look at the docs for java.lang.String#split(java.lang.String). It doesn't treat the argument as a simple string.
It is sorta covered in the JavaRanch Style Guide.
subject: split by pipe in a string