Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String Split problem  RSS feed

 
Andy Holm
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have fields that look like this: "M|F".

I want to split that String on the "|". However, it doesn't seem to work when I run the following code:



The result I get is every character (M, |, and F) is in its own array index. What am I doing wrong?
 
Henry Wong
author
Sheriff
Posts: 22866
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "|" has special meaning in a regex -- it is a OR operation for search patterns. If you actually want the literal "|", then you need to escape it as "\\|".

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!