RE: Isn't there a substring(start, end)-function????

Discussion in 'Python' started by Harvey Thomas, Aug 6, 2003.

  1. Dave wrote:
    > Hi all,
    >
    > Am I blind, or what? I can't find any quick way to do the following in
    > Python:
    >
    > substring(beginIndex, endIndex) witch returns the substring between
    > beginIndex and endIndex.
    >
    > Like:
    > text = "If someone attacks you with a banana"
    > print text.substring(0,3)
    > Should print "If "
    >
    > I've found absolutely everything else that I expect from a modern
    > programming language, but none of the modules (not even "string"!)
    > seems to have what I'm looking for.
    >
    > Please tell me I'm blind!
    >
    > Dave


    There isn't a substring function, because it's not necessary as slices do the job.
    The short answer is:

    text = "If someone attacks you with a banana"
    print text[0:3]

    but its explained much more fully in
    http://www.python.org/doc/current/tut/node5.html#SECTION005120000000000000000

    Harvey

    _____________________________________________________________________
    This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.
    Harvey Thomas, Aug 6, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave
    Replies:
    3
    Views:
    354
    Christopher Boomer
    Aug 6, 2003
  2. Noam Raphael
    Replies:
    17
    Views:
    505
    Noam Raphael
    May 26, 2004
  3. Replies:
    70
    Views:
    1,683
    Flash Gordon
    Jul 21, 2007
  4. KONTRA Gergely

    substring: to the end of the string

    KONTRA Gergely, Nov 14, 2003, in forum: Ruby
    Replies:
    16
    Views:
    203
    Jason DiCioccio
    Nov 18, 2003
  5. Replies:
    3
    Views:
    189
    Sherm Pendley
    Aug 3, 2005
Loading...

Share This Page