String Search?

Jason Alexander j_l_alexander at my-deja.com
Tue Feb 29 21:23:49 CET 2000


In article <doTu4.8481$al3.113009 at newsc.telia.net>,
  "Fredrik Lundh" <effbot at telia.com> wrote:
> Jason wrote:
> > As a pre-note: Having just picked up Python,
> > please excuse my ignorance.
>
> umm.  is that really a valid excuse for not
> having looked in the handbook? ;-)
>
> > How exactly do I search for a given string within
> > a string? i.e. how do I search for "foo" within
> > the sentence "the foo falls at midnight"? The
> > position of the string within the sentence isn't
> > important, just the existance.
>
> if string.find(mystring, "foo") >= 0:
>     ...
>
> or
>
> string.index(mystring, "foo")
> ...
>
> the latter raises a ValueError exception
> if the substring isn't found.
>
> for more info, see the "string" chapter in
> the library reference.
>
> hope this helps!
>
> </F>
>
>

Thank you very much, Fredrik. And, my apologies for hastily posting to
the newsgroups before digging through the documentation a bit better.

I assure you I'll be visiting a book store this week, and studying
up. :)

Thanks again,
-Jason



Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list