This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 336
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: 7684
    
  19

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