943,778 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 4686
  • Python RSS
May 29th, 2009
0

String search function

Expand Post »
Hi All,

I am using the .search function.
python Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 18
Solved Threads: 0
Posting Whiz in Training
dinilkarun is offline Offline
206 posts
since Feb 2008
May 29th, 2009
0

Re: String search function

Click to Expand / Collapse  Quote originally posted by dinilkarun ...
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...
Reputation Points: 10
Solved Threads: 2
Light Poster
Deepak.G is offline Offline
31 posts
since Jan 2009
May 29th, 2009
1

Re: String search function

If you want to just find out if one string is contained inside another:
python Syntax (Toggle Plain Text)
  1. strvalue1 in strvalue2

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

If you want to find the index of the first occurrence of one string in another:
python Syntax (Toggle Plain Text)
  1. ind = strvalue1.find(strvalue2)
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: how to create a web site using python lang.
Next Thread in Python Forum Timeline: any ideas?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC