aspose file tools*
The moose likes Beginning Java and the fly likes split ? 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 » Beginning Java
Bookmark "split ?" Watch "split ?" New topic
Author

split ?

Ganesan Ramakrishnan
Ranch Hand

Joined: Mar 18, 2008
Posts: 89
Hi,

I have a problem in string.split("|");

for example,



the above code not working properly.

i want to split the above string Ganesan and Ramakrishnan.

any suggestion would be appreciated.

Regards
Ganesan
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

The quick answer ll be, no allowed "pipe" | operator, See the docs for valid regex..

This thread discuss the rest ..


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42282
    
  64
The important point is that the argument to split is a regular expression, and that in regular expressions certain characters have special meaning, e.g. the "|" symbol. If those are to be used with their literal meaning they need to be escaped, which is done by preceding them with a backslash. Try using "\|".


Ping & DNS - my free Android networking tools app
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Don't try using regular expressions until you have read about them in the Java� Tutorials.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Originally posted by Ulf Dittmer:
The important point is that the argument to split is a regular expression, and that in regular expressions certain characters have special meaning, e.g. the "|" symbol. If those are to be used with their literal meaning they need to be escaped, which is done by preceding them with a backslash. Try using "\|".

Of course you need to escape the backslash as well because it's a Java escape character too so it should be "\\|"


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
wood burning stoves
 
subject: split ?