Combining some lines of text in a list?

Mike Bonner bonnmike at gmail.com
Mon Jan 30 20:09:36 EST 2012


Just tried it and ended up with the following. (made a stack with 2 fields,
1 with your sample text, other for output)

on mouseUp
   put field 1 into tVar
   set the itemdel to colon
   repeat for each line tLine in tVar
      switch item 1 of tLine
         case "name"
            put return & return &  tLine after tNewVar -- put the name line
into a holding var
            break
         case "description"
            put return &  tLine after tNewVar -- same as name. Puts
description on a new line in the holding var
            break
         case "creature1" -- if its creature 1, new line and put the whole
line
            put return & tLine after tNewVar
            break
         case "notes1" -- if its notes1, new line and put the whole line
            put return & tLine after tNewVar
            break
         default
-- everything that doesn't match the preceeding rules just take it on to
the end of the holding var
-- This assumes that the list is always correctly organized. (ie, name,
description, group of creatures, group of notes
            put space & item 2 of tLine after tNewVar
      end switch
   end repeat
   put tNewVar into field 2
   delete char 1 to 2 of field 2
end mouseUp

On Mon, Jan 30, 2012 at 5:45 PM, John Patten <johnpatten at mac.com> wrote:

> 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
>
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list