mutable string?

T

Torsten Mohr

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.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Torsten said:
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
 
J

John Roth

Torsten Mohr said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top