Re: 'string'.strip(chars)-like function that removes from the middle?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?iso-8859-1?q?C=E9dric_Lucantis?=

    Re: 'string'.strip(chars)-like function that removes from the middle?

    Hi,
    Greetings.
    >
    The strip() method of strings works from both ends towards the middle.
    Is there a simple, built-in way to remove several characters from a
    string no matter their location? (besides .replace() ;)
    >
    For example:
    .strip --'www.example.co m'.strip('cmowz .')
    'example'
    .??? ----- 'www.example.co m'.strip('cmowz .')
    'exaple'
    --
    I don't see any string method to do that, but you can use a regexp :
    >>re.sub('[cmowz.]', '', 'www.example.co m')
    'exaple'

    --
    Cédric Lucantis
Working...