Remove all whitespace in a string

后端 未结 11 1793
一整个雨季
一整个雨季 2020-11-22 04:02

I want to eliminate all the whitespace from a string, on both ends, and in between words.

I have this Python code:

def my_handle(self):
    sentence          


        
11条回答
  •  野性不改
    2020-11-22 04:35

    Be careful:

    strip does a rstrip and lstrip (removes leading and trailing spaces, tabs, returns and form feeds, but it does not remove them in the middle of the string).

    If you only replace spaces and tabs you can end up with hidden CRLFs that appear to match what you are looking for, but are not the same.

提交回复
热议问题