Connecting Tech Pros Worldwide Forums | Help | Site Map

Removing Space and "-" from a string

Ahmed, Shakir
Guest
 
Posts: n/a
#1: Jun 27 '08
I have thousands of records in MS Access database table, which records I
am fetching using python script. One of the columns having string like
'8 58-2155-58'

Desired output: '858215558'

I want to remove any spaces between string and any dashes between
strings. I could do it in access manually but want to do from python
script

Any help is highly appreciated.

sh

s0suk3@gmail.com
Guest
 
Posts: n/a
#2: Jun 27 '08

re: Removing Space and "-" from a string


On May 20, 11:02 am, "Ahmed, Shakir" <shah...@sfwmd.govwrote:
Quote:
I have thousands of records in MS Access database table, which records I
am fetching using python script. One of the columns having string like
'8 58-2155-58'
>
Desired output: '858215558'
>
I want to remove any spaces between string and any dashes between
strings. I could do it in access manually but want to do from python
script
>
Any help is highly appreciated.
string.replace('-', '').replace(' ', '')
Ahmed, Shakir
Guest
 
Posts: n/a
#3: Jun 27 '08

re: Removing Space and "-" from a string


Thanks, works exactly what I needed.

-----Original Message-----
From: python-list-bounces+shahmed=sfwmd.gov@python.org
[mailto:python-list-bounces+shahmed=sfwmd.gov@python.org] On Behalf Of
s0suk3@gmail.com
Sent: Tuesday, May 20, 2008 12:22 PM
To: python-list@python.org
Subject: Re: Removing Space and "-" from a string

On May 20, 11:02 am, "Ahmed, Shakir" <shah...@sfwmd.govwrote:
Quote:
I have thousands of records in MS Access database table, which records
I
Quote:
am fetching using python script. One of the columns having string like
'8 58-2155-58'
>
Desired output: '858215558'
>
I want to remove any spaces between string and any dashes between
strings. I could do it in access manually but want to do from python
script
>
Any help is highly appreciated.
string.replace('-', '').replace(' ', '')
--
http://mail.python.org/mailman/listinfo/python-list

Paul Hankin
Guest
 
Posts: n/a
#4: Jun 27 '08

re: Removing Space and "-" from a string


On May 20, 5:02*pm, "Ahmed, Shakir" <shah...@sfwmd.govwrote:
Quote:
I have thousands of records in MS Access database table, which records I
am fetching using python script. One of the columns having string like
'8 58-2155-58'
>
Desired output: '858215558'
>
I want to remove any spaces between string and any dashes between
strings. I could do it in access manually but want to do from python
script
'filter' returns a string if it's argument is a string, so works
nicely here.

def cleanup(s):
return filter(lambda x: x not in ' -', s)

--
Paul Hankin
Terry Reedy
Guest
 
Posts: n/a
#5: Jun 27 '08

re: Removing Space and "-" from a string



"Paul Hankin" <paul.hankin@gmail.comwrote in message
news:9d9dadfe-3f91-44a6-8b1b-50fe8003046d@e39g2000hsf.googlegroups.com...
On May 20, 5:02 pm, "Ahmed, Shakir" <shah...@sfwmd.govwrote:
Quote:
I have thousands of records in MS Access database table, which records I
am fetching using python script. One of the columns having string like
'8 58-2155-58'
>
Desired output: '858215558'
|def cleanup(s):
| return filter(lambda x: x not in ' -', s)

Or
Quote:
Quote:
Quote:
>>s='8 58-2155-58'
>>t=str.maketrans('','',' -')
>>s.translate(t)
'858215558'




Closed Thread