efficiently replace bad characters

前端 未结 6 1214
梦毁少年i
梦毁少年i 2020-12-07 21:28

I often work with utf-8 text containing characters like:

\\xc2\\x99

\\xc2\\x95

\\xc2\\x85

etc

<
6条回答
  •  温柔的废话
    2020-12-07 21:59

    If you want to remove all non-ASCII characters from a string, you can use

    text.encode("ascii", "ignore")
    

提交回复
热议问题