replace from end of string?

  • Thread starter Brian van den Broek
  • Start date
B

Brian van den Broek

Hi all,

in writing my response to Mark Leeds' recent question about replacing
text at the end of a string, I was moved to wonder if it wouldn't it
be handy if the replace method of string instances did one of the
following:

took a negative integer for count and interpreted that as replace the
absolute value of count many instance, but starting from the end of
the string, or,

had a default parameter from_end=False, such that if it were True,
replacements happened count many times, starting from the end?


I get that it isn't too much of a hassle to write a function to do
this (heck, *I* did it, so it cannot be too rough ;-). But, it seems a
common enough task to be a useful addition nevertheless. (And the
speed of the C implementation wouldn't hurt, either.)

Is there already a pre-rolled way to do this that I've overlooked? Or
some strong reason there oughtn't be?

Thanks, and best to all,

Brian vdB
 

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

No members online now.

Forum statistics

Threads
474,222
Messages
2,571,142
Members
47,757
Latest member
PDIJaclyn

Latest Threads

Top