aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about String.split execution Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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: 16695
    
  19

"-\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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: about String.split execution
 
Similar Threads
characters and numbers seperation in a string
LinkedHashMap - trying to use the method removeEldestEntry
"\d" vs "\\d" while tokenizing
trying to find union/intersection of arrays containing integers
String.split() method functionality