String search function

Thread Solved

Join Date: Feb 2008
Posts: 198
Reputation: dinilkarun is an unknown quantity at this point 
Solved Threads: 0
dinilkarun dinilkarun is offline Offline
Junior Poster

String search function

 
0
  #1
May 29th, 2009
Hi All,

I am using the .search function.
  1. strValue="XXX"
  2. strTemp1="YYYXXX"
  3. strTemp= strTemp1.search(strValue)
Python is not able to recognise the .search function.
AttributeError: 'str' object has no attribute 'search'

What should I import for this?
Please help!
Last edited by Tekmaven; May 30th, 2009 at 3:11 am. Reason: Code Tags
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 28
Reputation: Deepak.G is an unknown quantity at this point 
Solved Threads: 2
Deepak.G's Avatar
Deepak.G Deepak.G is offline Offline
Light Poster

Re: String search function

 
0
  #2
May 29th, 2009
Originally Posted by dinilkarun View Post
Python is not able to recognise the .search function.
AttributeError: 'str' object has no attribute 'search'
yes...that would be the response
to find the available methods for string class..try help(string) at the python prompt...
that shud help

Peace...
Deepak G
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,602
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: String search function

 
1
  #3
May 29th, 2009
If you want to just find out if one string is contained inside another:
  1. strvalue1 in strvalue2

If you want to find out how many occurrences of one string there are in another:
  1. num = strvalue.count(strvalue2)

If you want to find the index of the first occurrence of one string in another:
  1. ind = strvalue1.find(strvalue2)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC