Remove all newlines from inside a string
strip
only removes characters from the beginning and end of a string. You want to use replace
:
str2 = str.replace("\n", "")
re.sub('\s{2,}', ' ', str) # To remove more than one space
As mentioned by @john, the most robust answer is:
string = "a\nb\rv"
new_string = " ".join(string.splitlines())