472,110 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 software developers and data experts.

string.find for case insensitive search

Is there a good way how to use string.find function to find a
substring if I need to you case insensitive substring?
Thanks for reply
LL

Feb 7 '07 #1
11 51208
"Johny" <py****@hope.czwrote:
Is there a good way how to use string.find function to find a
substring if I need to you case insensitive substring?
s.lower().find(substring.lower())

Feb 7 '07 #2
lower() is also deprecated :) oh well

On 7 Feb 2007 21:06:08 GMT, Duncan Booth <du**********@invalid.invalidwrote:
"Johny" <py****@hope.czwrote:
Is there a good way how to use string.find function to find a
substring if I need to you case insensitive substring?

s.lower().find(substring.lower())

--
http://mail.python.org/mailman/listinfo/python-list
Feb 7 '07 #3
Johny a écrit :
Is there a good way how to use string.find function to find a
substring if I need to you case insensitive substring?
"abCdZEd".lower().find("BcD".lower())

Feb 7 '07 #4
Johny wrote:
Is there a good way how to use string.find function to find a
substring if I need to you case insensitive substring?
Thanks for reply
LL
Maybe something like:

x="my string I'm going to SEarCH"
hasword='SEARCH' in x.upper()
location=x.upper().find('SEARCH')

print hasword
True

print location
23
-Larry

Feb 7 '07 #5
string.find is deprecated as per the official python documentation.

take a look at the "re" module

On 7 Feb 2007 12:53:36 -0800, Johny <py****@hope.czwrote:
Is there a good way how to use string.find function to find a
substring if I need to you case insensitive substring?
Thanks for reply
LL

--
http://mail.python.org/mailman/listinfo/python-list
Feb 7 '07 #6
Don Morrison wrote:
lower() is also deprecated :) oh well
The string method .lower() is not deprecated.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Feb 7 '07 #7
"Don Morrison" <do*********@gmail.comwrote:
lower() is also deprecated :) oh well

On 7 Feb 2007 21:06:08 GMT, Duncan Booth
<du**********@invalid.invalidwrote:
>"Johny" <py****@hope.czwrote:
Is there a good way how to use string.find function to find a
substring if I need to you case insensitive substring?

s.lower().find(substring.lower())
No. RTFM and don't top post.

The functions such as lower() and find() in the string *module* are
deprecated. The methods are what you should use.

Feb 7 '07 #8
My apologies, I confused the built-in "str" with the module "string".
I was reading from the section of the 2.4.4 docs called: 4.1.4
Deprecated string functions

On 2/7/07, Robert Kern <ro*********@gmail.comwrote:
Don Morrison wrote:
lower() is also deprecated :) oh well

The string method .lower() is not deprecated.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list
Feb 7 '07 #9
Don Morrison wrote:
string.find is deprecated as per the official python documentation.
but the str.find() method isn't.
take a look at the "re" module
A possibility.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note: http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007

Feb 7 '07 #10
Don Morrison wrote:
string.find is deprecated as per the official python documentation.
but the str.find() method isn't.
take a look at the "re" module
A possibility.

regards
Steve
Thank you everyone. :) Johny did say "string.find" in his message, not
"str.find", but continue to proceed with flogging. thank you!
Feb 7 '07 #11
On Wed, 07 Feb 2007 13:09:00 -0800, Don Morrison wrote:
string.find is deprecated as per the official python documentation.

take a look at the "re" module
Regular expressions are way, WAY overkill for a simple find. Just use
the string methods. Instead of this:

import string
string.find("Norwegian Blue", "Blue")
just do this:

"Norwegian Blue".find("Blue")

For case insensitive find:

"Norwegian Blue".lower().find("Blue".lower())

(or better still, turn it into a function).
--
Steven D'Aprano

Feb 8 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ajay.sonawane | last post: by
3 posts views Thread by Guoqi Zheng | last post: by
reply views Thread by Dragan Matic | last post: by
1 post views Thread by ericswebber | last post: by
1 post views Thread by iksando | last post: by
4 posts views Thread by bb | last post: by
14 posts views Thread by Mosfet | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.