string.replace

Emile van Sebille emile at fenx.com
Fri May 5 13:13:58 EDT 2000


Don't confuse the display with the content.

Python 1.6a2 (#0, Apr  6 2000, 11:45:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
IDLE 0.6 -- press F1 for help
>>> import string
>>> s="asdasd'a'asddads"

>>> print len(s)
16
>>> string.replace(s,"'","\\'")
"asdasd\\'a\\'asddads"
>>> ns = string.replace(s,"'","\\'")
>>> print ns
asdasd\'a\'asddads
>>> print len(ns)
18
>>>

Emile van Sebille
emile at fenx.com
-------------------


----- Original Message ----- 
From: <rei05 at gmx.de>
To: <python-list at python.org>
Sent: Friday, May 05, 2000 10:12 AM
Subject: Re: Re: string.replace


> > On Fri, 5 May 2000 rei05 at gmx.de wrote:
> > > so i tried string.replace(s,"'","\'"), but this doesn`t work. 
> > 
> sorry, i forgot to mention, that i tried:
> > 
> > string.replace(s,"'","\\'")
> > 
> too, but the result of this is like the following:
> 
> >>> import string
> >>> s="asdasd'a'asddads"
> >>> string.replace(s,"'","\\'")
> "asdasd\\'a\\'asddads"
> 
> and i wish to have ...\'a\'..., not ...\\'a\\'...
> 
> -- 
> Sent through GMX FreeMail - http://www.gmx.net
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list
> 





More information about the Python-list mailing list