It's not a secret anymore!
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: 752

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: 8927

Angus Ferguson wrote:Any idea please?



Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
Matthew Brown

Joined: Apr 06, 2010
Posts: 4543

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.
I agree. Here's the link:
subject: split by pipe in a string
It's not a secret anymore!