stripping cr/lf, lf, cr

Jeff Sandys sandysj at asme.org
Tue Mar 27 11:21:14 EST 2001


deadmeat wrote:
> 
> Is there a platform independant function that will remove appropriate EOL
> characters from a string?  I don't want to use strip() since it will also
> remove other whitespace I want to keep.

Here is how I do it in windows and unix:

def trimcr(str):
	if str == '':
		return ''
	if str[-1:] in '\n\r':
		return trimcr(str[:-1])
	else:
		return str

Thanks,
Jeff Sandys



More information about the Python-list mailing list