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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "split ?" Watch "split ?" New topic
Author

split ?

Ganesan Ramakrishnan
Ranch Hand

Joined: Mar 18, 2008
Posts: 87
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: 39549
    
  27
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 - updated with new look and Ping home screen widget
Campbell Ritchie
Sheriff

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

Joined: Oct 27, 2005
Posts: 19544
    
  16

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: split ?
 
Similar Threads
Problem in internet Explorer?
Referencing to another object
Getting error when migrated the was 5.1 to 6.1
exact word match
Difference between String s = "java" and String s = new String("java");