| Author |
split method in string
|
Saathvik Reddy
Ranch Hand
Joined: Jun 03, 2005
Posts: 228
|
|
Hi, I have a simple string and want to split the string based on a regex. I am using split method to split the string For Example: Here the array size is zero. If i replace with str="fname,lname"; and use str.split(","); It works fine. Is there anything wrong with the period. Thanks, Srikanth.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16815
|
|
It works fine. Is there anything wrong with the period.
A period has special meaning in a regex. It means to match anything. So, if you want to match an actual period, you will need to escape it... use "\\." instead. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Saathvik Reddy
Ranch Hand
Joined: Jun 03, 2005
Posts: 228
|
|
Huh! it worked. Thanks Henry.
|
 |
Piet Verdriet
Ranch Hand
Joined: Feb 25, 2006
Posts: 266
|
|
Originally posted by Henry Wong: A period has special meaning in a regex. It means to match anything...
Except new line characters (by default).
|
 |
 |
|
|
subject: split method in string
|
|
|