Is there a pythonic way to do what the str.strip() method does, except for all occurrences, not just those at the beginning and end of a string?
Example:
>> '::2012-05-14 18:10:20.856000::'.strip(' -.:')
>> '2012-05-14 18:10:20.856000'
I want
>> '::2012-05-14 18:10:20.856000::'.crazy_function(' -.:')
>> '20120514181020856000'
Does Python provides me a built-in crazy_function???
I could easily do it programatically, but I want to know if there is a built-in for that.
Couldn’t find one. Thank you for your help.
Use the
translatefunction to delete the unwanted characters:Be sure your string is of
strtype and notunicode, as the parameters of the function won’t be the same. For unicode, use the following syntax ; it consists in building the dict of unicode ordinals from the chars to delete and to map them toNone:Some timings for performance comparison with
re: