common code patterns
Alex Tweedly
alex at tweedly.net
Fri Aug 11 11:42:28 EDT 2017
On 11/08/2017 16:26, Mark Wieder via use-livecode wrote:
>
> case 2:
> iterating through a cr-separated list and needing to modify lines
> (note: this is even more extreme if I need to delete lines):
>
> put tBreaks into tNewBreaks
> put 1 into tLine
> repeat for each line tBreak in tBreaks
> put item 1 of tBreak into tID
> put the long id of control id tID of the topstack into tObjectID
> put tObjectID into item 1 of line tLine of tNewBreaks
> add 1 to tLine
> end repeat
> return tNewBreaks
>
Is it really worth doing this by changing each of the lines ?
Is it not easier, clearer and very likely just as fast, to do:
> put empty into tNewBreaks
> repeat for each line tBreak in tBreaks
> put item 1 of tBreak into tID
> put the long id of control id tID of the topstack into tObjectID
> put tObjectID & the itemDel & item 2 to -1 of tBreak &CR after
> tNewBreaks
> end repeat
> return char 1 to -1 of tNewBreaks
With a bonus that deleting lines (i.e. not copying them) is easier.
Regards,
Alex
More information about the use-livecode
mailing list