File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about String.split execution

 
susana miranda
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"-\s" means a minus followed by a whitespace -- not a minus or a whitespace.

Henry
 
susana miranda
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic