Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Split function of String class

 
Sim Kim
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to use Split function of String class . But it does not seem to work fine .

Example :

"Hello@Hi@Bye".split("@") : Works fine

but :

"Hello|Hi|Bye".split("|") : Does not works as intended .

Can somebody tell me why delimiter character "|" cannot be used ?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"|" is a special character in regular expressions. You need to escape it
 
Sim Kim
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which all are the special characters . I guess "|" and "*" . Are there any more ?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[
\
^
$
.
|
?
*
+
(
)
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the doc for Pattern. You can make some pretty fancy delimiters!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic