Eliminate a list of characters from a string?
William Park
opengeometry at yahoo.ca
Thu Mar 27 15:46:46 EST 2003
Max <maxx at easynews.com> 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','')
>
> However, if the list of eliminated characters is long, it seems a bit
> inefficient.
It also doesn't work. 'STRING.*()' should be lower case. In any case,
os.system ("tr -d '1234567890'")
will solve your problem.
--
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
Linux solution for data management and processing.
More information about the Python-list
mailing list