Stripping new lines from strings?

Simon Brunning SBrunning at trisystems.co.uk
Wed Aug 23 07:24:23 EDT 2000


> From:	Matthew Schinckel [SMTP:matt at null.net]
> 
> > By default, string.split splits at whitespace, but it has an optional
> second
> > argument, which allows you to split by any string. Wouldn't it be nice
> if
> > string.strip and its siblings had a similar 2nd argument...
> 
> why not:
> 
> >>> string.join(string.split(str, '\n'))
> 
> Or would that be gloriously slow ?
> 
Speed isn't the problem - the problem with this is that it strips stuff out
of the middle as well as the ends. So:

>>> brian = '***words***words***'
>>> string.join(string.split(brian, '*'), '')
'wordswords'

But if split had a second argument, you could do:
>>>string.strip(brian, '*')
'words***words'

BTW, if this message turns up twice, I apologise. It hasn't shown up an hour
after first being sent the first time. 

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning at trisystems.co.uk






-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list