Strings in Python

Shawn Milo Shawn at Milochik.com
Thu Feb 8 11:39:42 EST 2007


On 8 Feb 2007 08:28:25 -0800, Johny <python at hope.cz> wrote:
> Playing a little more with strings, I found out that string.find
> function provides the position of
> the first occurance of the substring in the string.
> Is there a way how to find out all substring's position ?
> To explain more,
> let's suppose
>
> mystring='12341'
> import string
>
> >>> string.find(mystring ,'1')
> 0
>
> But I need to find the  possition the other '1' in mystring too.
> Is it possible?
> Or must I use regex?
> Thanks for help
> L
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Loop it -- once you know the index of the first character, add the
third argument to string.find(), which tells it the position at which
to start (the last find + 1).



More information about the Python-list mailing list