×

Discussion Board

Results 1 to 3 of 3

Thread: find in text

  1. #1
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    57

    find in text

    Example

    txt = "Python is great and it is simple."
    txt.find("is")

    The output is 7 but how to find out the next "is" word?

    If there are many similar words, how to find them all?
    Last edited by DrivingMobileInnovation; 2008-06-07 at 00:58.

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: find in text

    An improvised solution could be like this:
    Code:
    txt="Python is great and it is simple."  #The text in which to search
    
    word="is"  #The word to search for
    
    length=2  #The length of the word
    
    p=[]
    for i in range(len(txt)-length):
       if(txt[i:i+length]==word):p.append(i)  #Append the position to the list
    
    print p

  3. #3
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,795

    Re: find in text

    For core Python related issues, please refer to the documentation,

    http://docs.python.org/tut/tut.html

    Best Regards,
    Croozeus
    Pankaj Nathani
    www.croozeus.com

Similar Threads

  1. Replies: 13
    Last Post: 2008-01-04, 11:15
  2. Rich Text Editor and Dialog
    By sakhya in forum Symbian User Interface
    Replies: 0
    Last Post: 2005-04-28, 17:08
  3. Howto send LF in text mode SMS
    By Royessers in forum General Messaging
    Replies: 2
    Last Post: 2003-06-12, 09:47
  4. Append text
    By smlobo in forum Symbian User Interface
    Replies: 2
    Last Post: 2003-06-05, 03:42

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×