Deleting specific control characters(\n \r \t) from a string

后端 未结 6 1252
鱼传尺愫
鱼传尺愫 2021-02-20 11:36

I have quite large amount of text which include control charachters like \\n \\t and \\r. I need to replace them with a simple space--> \" \". What is the fastest way to do this

6条回答
  •  执念已碎
    2021-02-20 11:51

    You may also try regular expressions:

    import re
    regex = re.compile(r'[\n\r\t]')
    regex.sub(' ', my_str)

提交回复
热议问题