wood burning stoves 2.0*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "split by pipe in a string" Watch "split by pipe in a string" New topic
Author

split by pipe in a string

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 386
Hi

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

I am using the next code



In my file I have

Dod1|2|3


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

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

Any idea please?

Thanks

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Angus Ferguson wrote:Any idea please?

Try
fileLine.split("[|]")

Winston

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
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

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: http://aspose.com/file-tools
 
subject: split by pipe in a string