473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 51751
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ajay.sonawane | last post by:
How can I find the wheather the occurance substring is main string in wide char provided that the compasion should be case insensitive.
3
by: Guoqi Zheng | last post by:
Sir, To my experience, the string.indexof function is case sensitive. I need it to be case insensitive, how should I achieve this? -- Kind regards Guoqi Zheng guoqi AT meetholland dot com
0
by: Dragan Matic | last post by:
Is there a way to set up collation order to be case-insensitive? I.E. I need to have a column c with value 'ABC' and when I do a "select * from table where c = 'abc'" it finds the row with value...
2
by: John | last post by:
Does anyone know how to how to performance case-insensitive search on XML data type in SQLServer 2005? Or I have to convert all the xml data to lower case before I store it? Thanks in advance....
1
by: ericswebber | last post by:
Case Insensitive Search with Sensitive Replace -------------------------------------------------------------------- Need a REGEX case insensitve search & replace where case of found string is...
1
by: iksando | last post by:
Hello, I'm looking for solution in case insensitive search in MySql. Table exemple. CREATE TABLE `pozycje` ( `id` int(11) NOT NULL auto_increment, `eid` varchar(20) collate latin2_bin...
4
by: bb | last post by:
Hi, void fun(const std::map<std::string,int>& m1) { // How to make a case insensitive search of this map without making a copy? } cheers.
7
by: Adrian | last post by:
Why does std::strings find search from the begining of the string when pos >= (std::string::npos-3) I cant find anything in the standard that says what find should do if pos==npos in find I...
14
by: Mosfet | last post by:
Hi, what is the most efficient way of doing a case insensitive comparison ? I am trying to write a universal String class and I am stuck with the case insensitive part : TCHAR is a char in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.