| Author |
about String.split execution
|
susana miranda
Greenhorn
Joined: May 21, 2008
Posts: 9
|
|
Hi, I have the following code:
Here is the question, at time execution I get this:
%java TestSplit "15750 7632546 554 5858 648-7428 122%6756" "\d\d\d(-\s)?\d\d\d\d"
# tokens: 2
- 15750
- 554 5858 648-7428 122%6756
I was expecting this:
# tokens: 4
- >15750 <
- > <
- > <
- > 122%6756<
Why does this happen?
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
"-\s" means a minus followed by a whitespace -- not a minus or a whitespace.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
susana miranda
Greenhorn
Joined: May 21, 2008
Posts: 9
|
|
Yes, my mistake! :S
I tried with:
java TestSplit "15750 7632546 554 5858 648-7428 122%6756" "\d\d\d(-)?(\s)?\d\d\d\d\s"
and I got my result:
# tokens: 4
>15750 <
><
><
>122%6756<
Thaks a lot!
I hope not having this kind of mistakes on the exam.
|
 |
 |
|
|
subject: about String.split execution
|
|
|