Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > >>I often need to re-code for myself a small code snippet to define >>string.upto() and string.from(), which are used like :
FWIW this is pretty easy to do with str.split() and rsplit(): >> >># canonical examples >> >>>"1234456789".upto("45") >> >>'1234' "1234456789".split("45", 1)[0] '1234' >> >>>"123456dd987".from('d') >> >>'d987' "1234456789".rsplit("45", 1)[-1] '6789' >> >># if not found, return whole string >> >>>"hello, world !".upto("#") >> >>"hello, world !" "hello, world !".split("#", 1)[0] 'hello, world !' >> >>>u"hello, world !".from("#") >> >>u"hello, world !" "hello, world !".rsplit("#", 1)[-1] 'hello, world !' Kent -- http://mail.python.org/mailman/listinfo/python-list