problem splitting a string

Discussion in 'Java' started by shadykazan@gmail.com, Feb 9, 2007.

  1. Guest

    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 ?
     
    , Feb 9, 2007
    #1
    1. Advertisements

  2. Chris Dollin Guest

    wrote:

    > 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");


    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.

    --
    Chris "electric hedgehog" Dollin
    "No-one here is exactly what he appears." G'kar, /Babylon 5/
     
    Chris Dollin, Feb 9, 2007
    #2
    1. Advertisements

  3. Guest

    On Feb 9, 10:51 am, Chris Dollin <> wrote:
    > wrote:
    > > 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");

    >
    > 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.
    >
    > --
    > 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 !!
     
    , Feb 9, 2007
    #3
  4. 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.
     
    Stefan Schmiedl, Feb 9, 2007
    #4
  5. Sanjay Guest

    wrote:
    > 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 ?
    >


    May be this will help
    String [] array=data.split("\u0000", -1);
     
    Sanjay, Feb 13, 2007
    #5
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SnVzdGlu?=

    splitting a string into a drop down

    =?Utf-8?B?SnVzdGlu?=, Oct 25, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    347
  2. VB Programmer

    Question: Splitting A String

    VB Programmer, Feb 1, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    361
    VB Programmer
    Feb 1, 2006
  3. Replies:
    2
    Views:
    539
    Alan Moore
    Mar 31, 2005
  4. Angelo Secchi

    Problem in splitting a string

    Angelo Secchi, Jul 22, 2004, in forum: Python
    Replies:
    10
    Views:
    638
    Byron
    Jul 22, 2004
  5. Anthony Liu

    Problem splitting a string

    Anthony Liu, Oct 15, 2005, in forum: Python
    Replies:
    8
    Views:
    406
    Kent Johnson
    Oct 15, 2005
  6. Robert Kern

    Re: Problem splitting a string

    Robert Kern, Oct 15, 2005, in forum: Python
    Replies:
    3
    Views:
    324
    Kent Johnson
    Oct 15, 2005
  7. Replies:
    3
    Views:
    865
  8. Saladin Mundi

    String splitting problem

    Saladin Mundi, Dec 14, 2007, in forum: Ruby
    Replies:
    4
    Views:
    220
    Saladin Mundi
    Dec 17, 2007
Loading...