Remove all newlines from inside a string

后端 未结 7 1896
自闭症患者
自闭症患者 2020-11-28 09:02

I\'m trying to remove all newline characters from a string. I\'ve read up on how to do it, but it seems that I for some reason am unable to do so. Here is step by step what

7条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 09:56

    As mentioned by @john, the most robust answer is:

    string = "a\nb\rv"
    new_string = " ".join(string.splitlines())
    

提交回复
热议问题