*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about String.split execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "about String.split execution" Watch "about String.split execution" New topic
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: 18754
    
  40

"-\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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about String.split execution