• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

split ?

 
Ganesan Ramakrishnan
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The quick answer ll be, no allowed "pipe" | operator, See the docs for valid regex..

This thread discuss the rest ..
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 "\|".
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't try using regular expressions until you have read about them in the Java� Tutorials.
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 "\\|"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic