How do you read up to a specific character in a line of text?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • darktemp
    New Member
    • Feb 2010
    • 25

    How do you read up to a specific character in a line of text?

    I have a line of characters that need to be separated. One example is like this:

    513413;dialog_5 13413;Sally Mae has some jobs for you.;

    Three sets of data all split into three groups placed in one line. What I would like to do is be able to read each group up to the semicolon (obviously without including it when it becomes displayed or used in the program).

    So in conclusion I would just like to know a method that can either count or read the string (from a file) up to the semicolon. I am aware of string.read(siz e), but obviously size is needed and it is variable. Highly prefer having size given also.

    Thanks! :)
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    String method split() was made for situations like this.
    Code:
    >>> line = "513413;dialog_513413;Sally Mae has some jobs for you.;"
    >>> line.split(";")[0]
    '513413'
    >>> for item in line.split(";"):
    ... 	print item
    ... 	
    513413
    dialog_513413
    Sally Mae has some jobs for you.
    
    >>>

    Comment

    • darktemp
      New Member
      • Feb 2010
      • 25

      #3
      Thanks again bvdet! :]

      Comment

      Working...