find() a larger string within a smaller string
Gary Herron
gherron at islandtraining.com
Fri Nov 14 15:05:03 EST 2008
korean_dave wrote:
> stringa = "hi"
> stringb = "hiyoooo"
>
> I'd like it to return -1 when I do:
>
> returnVal = stringa.find(stringb);
>
> Instead, it treats stringa as "hi" and stringb as "hi".
>
No it doesn't. stringb is "hiyoooo" and it "treats" it that way.
(And just what do you mean by "treat"?)
> How do I solve this?
>
There is nothing to solve. The expression
stringa.find(stringb)
asks if "hi" contains "hiyoooo", and since it does not, it returns a -1 indicating so.
You'll have to describe what you expected and why you expected it before we will be able to see a problem that needs solving. (And then the problem will most likely be in your expectations, not in the find method.)
Gary Herron
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list