| Author |
doubt in string.split method
|
vicky chauhan
Ranch Hand
Joined: Nov 27, 2008
Posts: 41
|
|
Hello guys,
I have following data:
1||1||Abdul-Jabbar||Karim||1996||1974
I want to delimit the tokens.
Here the delimiter being "||".
My delimiter setter is:
However, String[] tokens = line.split(delimiter); is not giving required result.
Please help!!
Nik
|
 |
Raymond Tong
Ranch Hand
Joined: Aug 15, 2010
Posts: 156
|
|
Why would you start with "\"" and end with "\"" ?
and what if your delimiter doesn't need escape character?
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
can you explain what you are trying to do in setDelimiter method?
|
 |
Roshan Ramesh
Greenhorn
Joined: Jul 12, 2010
Posts: 8
|
|
Bit tricky. But still, it should not take much time to resolve.
Assuming that you came here for advise on the possible delimeters, let me know if the below code did helped you.
|
 |
vicky chauhan
Ranch Hand
Joined: Nov 27, 2008
Posts: 41
|
|
Roshan Ramesh wrote:Bit tricky. But still, it should not take much time to resolve.
Assuming that you came here for advise on the possible delimeters, let me know if the below code did helped you.
Here is how I did it:
String delimiter = "||";
Pattern pattern = Pattern.compile(Pattern.quote(delimiter));
String[] tokens = pattern.split(line);
This worked perfectly... and is more efficient too!! Thanks to Ray!!
|
 |
vicky chauhan
Ranch Hand
Joined: Nov 27, 2008
Posts: 41
|
|
Raymond Tong wrote:
Why would you start with "\"" and end with "\"" ?
and what if your delimiter doesn't need escape character?
Thanks Raymond.. I found a solution.. I have posted it in the last comment in this post..
|
 |
 |
|
|
subject: doubt in string.split method
|
|
|