471,872 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,872 software developers and data experts.

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 13265
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 Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.