How to strip spaces (' '), tabs (\t), newlines (\n) and carriage return (\r) from a string with Python

1 Answer

0 votes
import re

s = "    python \t java \n  c# \r   c c++      "

s = re.sub('\s+', ' ', s)
s = s.strip()

print(s)


'''
run:

python java c# c c++

'''

 



answered Mar 30, 2017 by avibootz
...