Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

split by pipe in a string

 
Isaac Ferguson
Ranch Hand
Posts: 839
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angus Ferguson wrote:Any idea please?

Try
fileLine.split("[|]")

Winston
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic