count string replace occurances

William Park opengeometry at yahoo.ca
Mon Jun 13 04:16:55 EDT 2005


Xah Lee <xah at xahlee.org> wrote:
> if i have
> mytext.replace(a,b)
> how to find out many many occurances has been replaced?

If 'a' and 'b' are different length,
    - Count the string length, before and after.  The difference should
      be multiple of difference between length of 'a' and 'b'.

If they are same length, 
    - Split 'mytext', and count items.

-- 
William Park <opengeometry at yahoo.ca>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
	   http://home.eol.ca/~parkw/thinflash.html



More information about the Python-list mailing list