Eliminate a list of characters from a string?
Peter Hansen
peter at engcorp.com
Thu Mar 27 15:24:36 EST 2003
Max wrote:
>
> What is the simplest method (that does not perform too poorly) for eliminating
> any of a list of characters from a string. Currently, I ahev a script that used
> multiple string.replace statements. In other words, if I have the string
> 'A1B2C3' and want to eliminate the numbers leaving 'ABC' I could use:
>
> S1='A1B2C3'
> S2=STRING.REPLACE(S1,'1','')
> S2=STRING.REPLACE(S2,'2','')
> S2=STRING.REPLACE(S2,'3','')
Of course, Python is case-sensitive still, so this won't exactly work as-is...
(I'm sure you knew that, but perhaps newcomers would get confused by it.)
More information about the Python-list
mailing list