mutable string?

Discussion in 'Python' started by Torsten Mohr, Jan 16, 2005.

  1. Torsten Mohr

    Torsten Mohr Guest

    Hi,

    is there some string class that i can change in place,
    like perls strings?

    Is it possible to do some regex replacement functions
    that would even change its length?

    Can i append to this string?

    Is there some wrapper for C++ STL string class (if that
    would make sense)?


    Thanks,
    Torsten.
     
    Torsten Mohr, Jan 16, 2005
    #1
    1. Advertising

  2. Torsten Mohr wrote:
    > is there some string class that i can change in place,
    > like perls strings?


    array.array is mutable. You can use the 'c' code if
    you want an array of characters.

    > Is it possible to do some regex replacement functions
    > that would even change its length?


    You can't use re.sub array, but you can use re.search,
    and you can perform slice assigment.

    > Can i append to this string?


    Yes.

    > Is there some wrapper for C++ STL string class (if that
    > would make sense)?


    It would be possible, but I cannot see why one would want
    to do that.

    Regards,
    Martin
     
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=, Jan 16, 2005
    #2
    1. Advertising

  3. Torsten Mohr

    John Roth Guest

    "Torsten Mohr" <> wrote in message
    news:csdj61$bhm$...
    > Hi,
    >
    > is there some string class that i can change in place,
    > like perls strings?
    >
    > Is it possible to do some regex replacement functions
    > that would even change its length?
    >
    > Can i append to this string?
    >
    > Is there some wrapper for C++ STL string class (if that
    > would make sense)?


    A mutable string class would be fairly useful; as Martin
    says in his post, you can use the array.array class, but
    that doesn't have all of the useful string methods.

    It might not be as useful as one would think at first
    glance, however. The only operation that's fast on
    the typical array implementation is replacement of
    same size substrings; anything that involves a size
    change requires either moving lots of characters
    around, reallocating memory or both. For most
    applications, the workarounds involving lists of
    small strings would probably be faster.

    Writing it and getting it accepted into the core
    would be a major project, and so far the idea doesn't
    seem to have attracted anyone who wants to do that
    much work. The process starts with writing a PEP
    so it can be discussed.

    John Roth
    >
    >
    > Thanks,
    > Torsten.
    >
     
    John Roth, Jan 16, 2005
    #3
    1. Advertising

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. George Armhold
    Replies:
    1
    Views:
    1,471
    Chris Riesbeck
    Sep 2, 2004
  2. Dirk Schumann

    Cannot draw on mutable image

    Dirk Schumann, Dec 27, 2004, in forum: Java
    Replies:
    0
    Views:
    440
    Dirk Schumann
    Dec 27, 2004
  3. Replies:
    31
    Views:
    1,126
    Ingo R. Homann
    Aug 16, 2005
  4. Pierre Thibault

    Mutable String

    Pierre Thibault, May 3, 2006, in forum: Python
    Replies:
    2
    Views:
    513
    Pierre Thibault
    May 4, 2006
  5. Vincent RICHOMME
    Replies:
    12
    Views:
    711
    kwikius
    May 29, 2006
Loading...

Share This Page