On Sun, Dec 6, 2009 at 10:47 PM, Dr. Phillip M. Feldman <span dir="ltr"><<a href="mailto:pfeldman@verizon.net">pfeldman@verizon.net</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br>
I wrote a handy-dandy function (see below) called "strip_pairs" for stripping<br>
matching pairs of characters from the beginning and end of a string.  This<br>
function works, but I would like to be able to invoke it as a string method<br>
rather than as a function.  Is this possible?<br></blockquote><div><br></div><div>No. String objects are immutable and you can not set new attributes/methods on the type itself.</div><div><br></div><div>Really the best thing to do in this case is to just have this in an easy to access library, and call it as a function and not a string method.</div>

<div><br></div><div>The only alternative is to create a string subtype which has a new method-- but that would require all the strings you're using to be this subclass. E.g. you'd have to do MyString(regular_String) for each. This is really IMHO unwieldy and not really worth the effort -- just put strip_pairs into a library and call it as a function.</div>

<div> </div></div><div name="mailplane_signature">--S</div>