469,356 Members | 1,973 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

Removing Space and "-" from a string

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
Jun 27 '08 #1
4 12560
On May 20, 11:02 am, "Ahmed, Shakir" <shah...@sfwmd.govwrote:
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(' ', '')
Jun 27 '08 #2
Thanks, works exactly what I needed.

-----Original Message-----
From: py***********************************@python.org
[mailto:py***********************************@pytho n.org] On Behalf Of
s0****@gmail.com
Sent: Tuesday, May 20, 2008 12:22 PM
To: py*********@python.org
Subject: Re: Removing Space and "-" from a string

On May 20, 11:02 am, "Ahmed, Shakir" <shah...@sfwmd.govwrote:
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(' ', '')
--
http://mail.python.org/mailman/listinfo/python-list

Jun 27 '08 #3
On May 20, 5:02*pm, "Ahmed, Shakir" <shah...@sfwmd.govwrote:
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
Jun 27 '08 #4

"Paul Hankin" <pa*********@gmail.comwrote in message
news:9d**********************************@e39g2000 hsf.googlegroups.com...
On May 20, 5:02 pm, "Ahmed, Shakir" <shah...@sfwmd.govwrote:
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
>>s='8 58-2155-58'
t=str.maketrans('','',' -')
s.translate(t)
'858215558'


Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.