Re: Howto parse a string using a char in python

Discussion in 'Python' started by Tim Chase, Feb 15, 2013.

  1. Tim Chase

    Tim Chase Guest

    On 2013-02-15 18:04, Steve Goodwin wrote:
    > Hi,
    >
    > I am looking for the python2.7 function(s) to parse a string from a
    > colon character ":"
    >
    > Sounds simple enough.
    >
    > For example, a string like "123456:789". I just need the "123456"
    > substring.(left of the :)
    >
    > I have looked at regular expressions and string functions, so far
    > no luck. Custom function required?


    With just a single character, it sounds like you want something like

    whole = "123456:789"
    parts = whole.split(':') # or .split(':', 1)
    interesting = parts[0]

    No custom function needed.

    -tkc
     
    Tim Chase, Feb 15, 2013
    #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. Replies:
    19
    Views:
    1,157
    Daniel Vallstrom
    Mar 15, 2005
  2. lovecreatesbeauty
    Replies:
    1
    Views:
    1,099
    Ian Collins
    May 9, 2006
  3. John Gordon
    Replies:
    0
    Views:
    103
    John Gordon
    Feb 15, 2013
  4. David Robinow
    Replies:
    0
    Views:
    123
    David Robinow
    Feb 15, 2013
  5. Mark Lawrence
    Replies:
    0
    Views:
    127
    Mark Lawrence
    Feb 15, 2013
Loading...

Share This Page