Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

split method with regex

Thread view: 
josh - 26 Jun 2007 10:50 GMT
Hi I don't understand this output:

I have this string  b = "boo:and:foo";

than I do:

String s[] = b.split("o");

than s [] has:

 "b", "", ":and:f", "", ""

but why empty string??

Thanks
Chris Dollin - 26 Jun 2007 11:43 GMT
> Hi I don't understand this output:
>
[quoted text clipped - 9 lines]
>
> but why empty string??

There's an empty string between the two `o`s of `boo`, ditto `foo`,
isn't there?

Signature

Chris "the void permeates us all" Dollin

Hewlett-Packard Limited     Cain Road, Bracknell,                registered no:
registered office:          Berks RG12 1HN                       690597 England

josh - 26 Jun 2007 12:39 GMT
> > Hi I don't understand this output:
>
[quoted text clipped - 12 lines]
> There's an empty string between the two `o`s of `boo`, ditto `foo`,
> isn't there?

sorry which string? I don't see it!
Nigel Wade - 26 Jun 2007 14:21 GMT
>> > Hi I don't understand this output:
>>
[quoted text clipped - 14 lines]
>
> sorry which string? I don't see it!

That's because it isn't there. How can you see it if it isn't there?

"o" is the delimiter. Your original string is:

b[delimiter][delimiter]:and:f[delimiter][delimiter]

remove the [delimiter]s and you are left with:

"b", "", ":and:f, "" and "".

The first string is what appears before the first delimiter. The second string
is what appears between the first and second delimiter i.e. nothing. The third
string is between the 2nd and 3rd delimiters. The 4th string is between the 3rd
and 4th delimiters, again nothing. The final string is what appears after the
final delimiter, nothing.

"I saw a string that wasn't there,
It wasn't there again today
O how I wish that string would go away"

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Philipp Leitner - 26 Jun 2007 22:19 GMT
> > There's an empty string between the two `o`s of `boo`, ditto `foo`,
> > isn't there?
>
> sorry which string? I don't see it!

:) Thats kind of the point of an empty string, isn't it?

Do understand whats happening just look at your String again:

"boo:and:foo"

Your separator is 'o', therefore everything between two 'o's becomes a
string in your result array. Considering this it is obvious that 'oo'
will always yield an empty string, since there is nothing (i.e. an
empty string) between these two 'o's ...
Roedy Green - 29 Jun 2007 03:58 GMT
>Hi I don't understand this output:
>
[quoted text clipped - 11 lines]
>
>Thanks

replace all o's with commas. It should then appear logical.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.