Remove all newlines from inside a string

后端 未结 7 1866
自闭症患者
自闭症患者 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())
    
    0 讨论(0)
提交回复
热议问题