Item Subject: cc:Mail Text
I love it when code just "comes together."
I need to parse a line (actually several) of comma-separated fields, like
john,brown,ca,95014
My first thought was to use
setvar first_name word( line,,1 )
setvar last_name word( line,,2 )
setvar state word( line,,3 )
setvar zip word( line,,4 )
(These aren't the real fields; this is just an example.)
But what happens if 'city' is added later, between 'last_name' and 'state'?
I would have to renumber the indices for 'state' and 'zip'.
It turns out that the 4th and 5th parms to word() -- the resulting index
after the parse, and the starting index for the parse -- can be the same
field name! So, while not as obvious which field is being referenced,
the following should be more maintainable:
setvar first_name word( line,,1,x)
setvar last_name word( line,,1,x,x )
setvar state word( line,,1,x,x )
setvar zip word( line,,1,x,x )
Adding 'city' requires inserting one line, and NO other modification
to the code!
This is probably "old hat" to many of you, but I just thought
it was really cool.
Great job, Jeff Vance! :)
--Glenn Cole
Software al dente, Inc.
[log in to unmask]
|