mutable string?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Torsten Mohr

    #1

    mutable string?

    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.

  • Martin v. Löwis

    #2
    Re: mutable string?

    Torsten Mohr wrote:[color=blue]
    > is there some string class that i can change in place,
    > like perls strings?[/color]

    array.array is mutable. You can use the 'c' code if
    you want an array of characters.
    [color=blue]
    > Is it possible to do some regex replacement functions
    > that would even change its length?[/color]

    You can't use re.sub array, but you can use re.search,
    and you can perform slice assigment.
    [color=blue]
    > Can i append to this string?[/color]

    Yes.
    [color=blue]
    > Is there some wrapper for C++ STL string class (if that
    > would make sense)?[/color]

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

    Regards,
    Martin

    Comment

    • John Roth

      #3
      Re: mutable string?

      "Torsten Mohr" <tmohr@s.netic. de> wrote in message
      news:csdj61$bhm $2@schleim.qwe. de...[color=blue]
      > 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)?[/color]

      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[color=blue]
      >
      >
      > Thanks,
      > Torsten.
      >[/color]

      Comment

      Working...