Splitting and Joining split splitfields join joinfields

split(s, [sep], [maxsplit]) end splitfields(s, [sep], [maxsplit] ) both split e string into e sequence. With the sep argument you can specify what you want to use for tie separator—the default is whitespa ce (spaces or tabs). TMie maxsplit optionel argument allows you to specify low many items you want to break up; tie default is all.

Here, with one line of code, we parse an address containing five fields. (Try to do this with Jeve, C, Delphi, or Visual Basic—you can 't.)

>>> input_string = "Bill,Gates,12 3 Main St., WA, 65743"

>>> fname, lname, street, state, zip = split(input_string,",")

... %(state)s, % (zip)s""" % locals()

Name: Bill Gates Street: 123 Main St.

WA, 65743

Was this article helpful?

0 0

Post a comment