By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,784 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,784 IT Pros & Developers. It's quick & easy.

string.find for case insensitive search

P: n/a
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
Share this Question
Share on Google+
11 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.