• Post Reply Bookmark Topic Watch Topic
  • New Topic

Delimiters in String split  RSS feed

 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know adjacent delimiters create empty token but is there any exception regarding last pair of delimiters ??

String a[]=":ab::cde :fg::".split(":"); // Creates 5 tokens
String a[]=":ab::cde :fg:: -Space-".split(":"); // Creates 7 tokens
 
Tim Cooke
Marshal
Posts: 4039
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to have answered, and even proved, your own question.

Is there some part you don't understand?
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so there is really an exception to the empty token rule, the last pair (if not followed by anything) does not create an empty token .
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to see what tokens are actually produced, I suggest this code:


 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shubham Semwal wrote:so there is really an exception to the empty token rule, the last pair (if not followed by anything) does not create an empty token .


It is also documented (in the JavaDoc) as such. If you want the trailing empty matches, there is an overloaded split() method for it.

Henry
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok .. got it Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!