Removing unwanted characters from a string in Python

前端 未结 9 1889
暖寄归人
暖寄归人 2021-01-18 09:06

I have some strings that I want to delete some unwanted characters from them. For example: Adam\'sApple ----> AdamsApple.(case insensitive) Can someone help

9条回答
  •  野的像风
    2021-01-18 09:55

    One simple way:

    >>> s = "Adam'sApple"
    >>> x = s.replace("'", "")
    >>> print x
    'AdamsApple'
    

    ... or take a look at regex substitutions.

提交回复
热议问题