string manipulation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sovixi
    New Member
    • Mar 2007
    • 13

    string manipulation

    hi,

    I want to remove all the words in a string after certain point i.e. I'm looking for word "-----Original" and then I want to remove everything that fallows. How can I do this? Should I use list or maybe there are string functions that I can use?
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by sovixi
    hi,

    I want to remove all the words in a string after certain point i.e. I'm looking for word "-----Original" and then I want to remove everything that fallows. How can I do this? Should I use list or maybe there are string functions that I can use?
    You wand to find the index and use a slice:

    >>> s = "This is a test of the find function"
    >>> i = s.find("test")
    >>> s[:i]
    'This is a '
    >>>

    Comment

    • sovixi
      New Member
      • Mar 2007
      • 13

      #3
      thanks, so easy and it works. I was playing with list, remove, etc. and couldn't get anywhere.

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by sovixi
        thanks, so easy and it works. I was playing with list, remove, etc. and couldn't get anywhere.
        You are quite welcome.

        Comment

        Working...