Testing for the first few letters of a string

Alexnb alexnbryan at gmail.com
Thu Aug 7 17:40:22 CEST 2008

Okay, I have a fix for this problem, but it is messy and I think there might
be a better way. Heres an example:

Lets say I have a string: "My name is alex"

and I have another string "My name is alex, and I like pie". 

I want to test to see if just the "My name is alex" part is there. I don't
care about the pie part. 
My first instinct was to just create a for loop and test for the string like

n = 0

for x in string1:
      if string1[n] == string2[n]
            n = n +0
and then later testing to see what n was = to and figuring out if it got
through the whole loop. I feel like there should be an easier way to do
this, and probably is. So Does anyone have a suggestion?
View this message in context: http://www.nabble.com/Testing-for-the-first-few-letters-of-a-string-tp18873375p18873375.html
Sent from the Python - python-list mailing list archive at Nabble.com.

More information about the Python-list mailing list