Remove Whitespace
Jay Parlar
jparlar at cogeco.ca
Thu Apr 13 18:35:07 EDT 2006
On Apr 13, 2006, at 12:09 PM, Kelvie Wong wrote:
> try this:
>
> string = 'D c a V e r " = d w o r d : 0 0 0 0 0 6 4 0'
> import re
> re.sub("\s", "", string)
>
> On 4/13/06, david brochu jr <brochu121 at gmail.com> wrote:
>
Even easier (if you only want to replace blank spaces, and not all
whitespace):
string = 'D c a V e r " = d w o r d : 0 0 0 0 0 6 4 0'
string.replace(" ", "")
Note to the original poster: It's a *bad* idea to call a variable
'string', as there's already a module in the standard library called
'string'.
Jay P.
More information about the Python-list
mailing list