Remove all line breaks from a long string of text

前端 未结 8 1934
长发绾君心
长发绾君心 2020-11-28 19:53

Basically, I\'m asking the user to input a string of text into the console, but the string is very long and includes many line breaks. How would I take the user\'s string a

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 20:44

    The problem with rstrip is that it does not work in all cases (as I myself have seen few). Instead you can use - text= text.replace("\n"," ") this will remove all new line \n with a space.

    Thanks in advance guys for your upvotes.

提交回复
热议问题