I
ikshefem
I often need to re-code for myself a small code snippet to define
string.upto() and string.from(), which are used like :
# canonical examples
# if not found, return whole string
# It can be negative, too
# useful example
(I admit I am only using upto, but ...)
Nothing very complicated to make with find and rfind, but wouldn't this
be handy to have it ready in the common string method ?
string.upto() and string.from(), which are used like :
# canonical examples
'd987'"1234456789".upto("45") '1234'
"123456dd987".from('d')
# if not found, return whole string
u"hello, world !""hello, world !".upto("#") "hello, world !"
u"hello, world !".from("#")
'987'"123456dd987".from('d',2) # second integer argument
# It can be negative, too
"131"'192.168.179.131'.upto(".",-1) "192.168.179"
"192.168.179.131".from('.',-1)
# useful example
"first line of bigstring"bigstring.upto("\n")
(I admit I am only using upto, but ...)
Nothing very complicated to make with find and rfind, but wouldn't this
be handy to have it ready in the common string method ?