Skip to content Skip to sidebar Skip to footer

Compare Strings With Newlines In Them?

I'm trying to develop a script which compares a runtime generated string against one which is input by the user. Unfortunately, since user inputs his code using a textbox, I get ^M

Solution 1:

You should use str.splitlines() to split the text coming from the textbox, instead of whatever it is you're using now. That method handles \r\n properly.

Solution 2:

mystring.rstrip('\r') will return a new string with any ^M removed from the end of the string.

Post a Comment for "Compare Strings With Newlines In Them?"