Combining some lines of text in a list?

John Patten johnpatten at mac.com
Mon Jan 30 19:45:34 EST 2012


Hi All...

I have a list of items. The items in the list are in similar groups but each group is delimited by a tab.

For example:

name:Group1
description:Animals with four legs.
creature1:cats
creature2:dogs
notes1:Animals that are pets.
notes2:Animals that have fur.


name:Group 2 
description:Animals that swim.
creature1:sharks 
creature2:tuna
creature3:whales
notes1:Animals that live in the sea.
notes2:Animals that don't have fur.

etc. etc....

The items in the list are formatted identical. It is just the content after the colon that changes.

How would I go about combining the "creature" line (line 3) with the other creature lines for each item in list?

Ultimately I would like my items in my list to look like:

name:Group1
description:Animals with four legs.
creature1:cats dogs
notes1:Animals that are pets.
notes2:Animals that have fur.

name:Group 2 
description:Animals that swim.
creature1:sharks tuna whales
notes1:Animals that live in the sea.
notes2:Animals that don't have fur.

I have been experimenting with:

on mouseUp
   set the itemdel to tab
   put 2 into x
   put 1 into y
   repeat for number of items in cd fld "data" - 1
      put item x of cd fld "data" into tTempData
      put lineOffSet("creature1:", tTempData) into tTextStart --4
      put lineOffSet("notes1:", tTempData) into tTextEnd
      repeat for number of lines in tTempData
      put char 1 to 10 of line (tTextStart + y) of tTempData into tFirst
      put char 1 to 7 of line tTextEnd of tTempdata into tEnd
      if tFirst <> tEnd then 
         put line (tTextStart + y) of tTempData after tAdditionalText
         put empty into line (tTextStart + y) of tTempData
         add 1 to y
         put tTempData & tab & return after tFormattedData
      else
        put item x of tTempData & tab & return after tFormattedData
         --put item x of tTempData after tFormattedData
        add 1 to x
        add 1 to y
         end if
      end repeat
      add 1 to x
      
      end repeat
      put tFormattedData
end mouseUp

But I'm thinking there must be an easier way? Any suggestions?

Thank you!

John Patten
SUSD






More information about the use-livecode mailing list