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 / February 2007

Tip: Looking for answers? Try searching our database.

problem splitting a string

Thread view: 
shadykazan@gmail.com - 09 Feb 2007 08:40 GMT
hi im trying to split a string into an array using string.split
my delimiter is the null character '\u0000'
the problem is that when there are 2 or more consecutive null
characters at the end of the string,
they don't get split and java ignores them,but if in the middle of the
string it works fine.
i have tried inserting a space between each 2 consecutive nulls

data.replaceAll("\u0000{2}","\u0000 \u0000");
String [] array=data.split("\u0000");

but it did not work, im not so good at regular expressions but i think
this should've worked
maybe there is another solution, other then this one or another way to
split the string  !
any ideas ?
Chris Dollin - 09 Feb 2007 08:51 GMT
> hi im trying to split a string into an array using string.split
> my delimiter is the null character '\u0000'
[quoted text clipped - 5 lines]
>
> data.replaceAll("\u0000{2}","\u0000 \u0000");

You've done a `.replaceAll` on `data` and discarded the result. replaceAll
does not change the subject string -- it can't, since String's are
immutable. It returns the modified string.

Signature

Chris "electric hedgehog" Dollin
"No-one here is exactly what he appears." G'kar, /Babylon 5/

shadykazan@gmail.com - 09 Feb 2007 09:13 GMT
> shadyka...@gmail.com wrote:
> > hi im trying to split a string into an array using string.split
[quoted text clipped - 14 lines]
> Chris "electric hedgehog" Dollin
> "No-one here is exactly what he appears." G'kar, /Babylon 5/

woops thanks man
sorry it was a stupid mistake !!
Stefan Schmiedl - 09 Feb 2007 12:03 GMT
On Fri, 09 Feb 2007 00:40:34 -0800, shadykazan wrote:

> hi im trying to split a string into an array using string.split
> my delimiter is the null character '\u0000'
> ...
> maybe there is another solution, other then this one or another way to
> split the string  !
> any ideas ?

RTFjavadoc on String.split ... it has another parameter to solve exactly
your problem.

s.
Sanjay - 13 Feb 2007 04:09 GMT
> hi im trying to split a string into an array using string.split
> my delimiter is the null character '\u0000'
[quoted text clipped - 12 lines]
> split the string  !
> any ideas ?

May be this will help
String [] array=data.split("\u0000", -1);


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



©2008 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.