File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes String Split problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "String Split problem" Watch "String Split problem" New topic
Author

String Split problem

Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
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

Joined: Sep 28, 2004
Posts: 19070
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String Split problem