I have to split a string based on "\" symbol. But, it is throwing exception.
String str = "ram\raj";
String strs[] = str.split("
");
for (int i=0; i<strs.length; i++ )
{
System.out.println(str);
}
I have tried in the second model also. But, failed.
System.out.println(str.substring(str.indexOf("
")+1));
-
problem with split function when the delimiter is "\" (2 messages)
- Posted by: Mr. Ram
- Posted on: May 02 2008 06:37 EDT
Threaded Messages (2)
- Re: problem with split function when the delimiter is "" by Rakesh Malpani on May 02 2008 09:56 EDT
- Re: problem with split function when the delimiter is "" by Sunil Joshi on May 02 2008 10:06 EDT
-
Re: problem with split function when the delimiter is ""[ Go to top ]
- Posted by: Rakesh Malpani
- Posted on: May 02 2008 09:56 EDT
- in response to Mr. Ram
String strs[] = str.split("\\\\"); You need to realize that the "" is a regular expression.. so back slash needs to be escaped for the reg exp too. Regards, Rakesh. -
Re: problem with split function when the delimiter is ""[ Go to top ]
- Posted by: Sunil Joshi
- Posted on: May 02 2008 10:06 EDT
- in response to Rakesh Malpani
Your original string is not properly escaped. First of all the program should not get compiled. your string should be "ram
raj"