Speaking of Filter and Match...

Dick Kriesel dick.kriesel at mail.com
Mon Mar 14 20:08:56 EDT 2022

> On Mar 13, 2022, at 1:05 PM, J. Landman Gay via use-livecode <use-livecode at lists.runrev.com> wrote:
> On 3/12/22 8:54 PM, Roger Guay via use-livecode wrote:
>> I have a field with about a thousand lines with many duplicate lines, and I want to delete the duplicates. Seems like this should be simple but I am running around in circles. Can anyone help me with this?
> Making the list into an array is the easiest way but as mentioned, it will destroy the original order. If the order is important then you can restore it with a custom sort function...

Since order must be maintained, it’s probably faster not to split and sort, and faster not to scan the list repeatedly using lineOffset or contains.
You could do it like this:

command removeDuplicates pDelimitedList, pDelimiter
   local tArray, tList
   set the lineDelimiter to pDelimiter
   repeat for each line tLine in pDelimitedList
      if not tArray[tLine] then -- i.e., if this line hasn't appeared already, then ...
         put true into tArray[tLine]
         put tLine & pDelimiter after tList
      end if
   end repeat
   delete last char of tList
   return tList for value
end removeDuplicates

— Dick

More information about the use-livecode mailing list