Finding list items within a table field

Peter M. Brigham pmbrig at gmail.com
Sat Jul 20 12:55:24 EDT 2013


Sorry for the late reply, but I'm catching up after some time off for my daughter's wedding….

This might be useful:

function lineOffsets str,container
   -- returns a comma-delimited list of all the lineOffsets of str in cntr
   -- duplicates are stripped out
   -- requires offsets()
   put offsets(str,container) into offList
   if offList = "0" then return "0"
   repeat for each item i in offList
      put the number of lines of (char 1 to i of container) into lineNbr
      put 1 into A[lineNbr]
      -- using an array avoids duplicates
   end repeat
   put the keys of A into loList
   sort lines of loList ascending numeric
   replace cr with comma in loList
   return loList
end lineOffsets

function offsets str,container,includeOverlaps
   -- returns a comma-delimited list of all the offsets of str in container
   -- returns 0 if not found
   -- third param is optional:
   --     offsets("xx","xxxxxx") returns "1,3,5" not "1,2,3,4,5"
   --     ie, by default, overlapping offsets are not counted
   --     if you want overlapping offsets then pass "true" in 3rd param
   if str is not in container then return 0
   if includeOverlaps = empty then put false into includeOverlaps
   put empty into offsetList
   put 0 into startPoint
   repeat
      put offset(str,container,startPoint) into thisOffset
      if thisOffset = 0 then exit repeat
      add thisOffset to startPoint
      put startPoint & comma after offsetList
      if not includeOverlaps then
         add length(str)-1 to startPoint
      end if
   end repeat
   return item 1 to -1 of offsetList -- delete trailing comma
end offsets

You could get the lineoffsets of each string and run a repeat loop to set the color of the lines.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig


On Jul 14, 2013, at 11:00 AM, Keith Clarke wrote:

> Hi folks,
> I've posted this question to Stack Overflow - http://stackoverflow.com/questions/17639968/livecode-find-list-items-within-a-table-field - but it seems very quiet over there on LiveCode matters, so apologies for t the cross-posting.
> 
> I'm trying to use LiveCode to clean up some contact data. I have two lists:
> 	SourceList: a list of tab-delimited contact records in a LiveCode table field;
> 	FlagList: a list of strings, such as 'test' that I want to check for within the SourceList.
> Ideally, I want to highlight 'hits' in both the FlagList rows and the matching characters in the items in the rows of the SourceList, but I'm struggling with errors on my first pass. 
> 
> On loading the SourceList from file, I'm trying to set the colour of any FlagList field rows that are found in the SourceList.
> 
> Here's the script on the 'Load SourceList' button...
> 
> on mouseUp
>   answer file "Select text file to Clean" with type "txt"
>   if it <> "" then
>      put empty into field "SourceList"
>      put it into field "SourceFile"
>      put it into theFilePath
>      put URL ("file:" & theFilePath) into field "SourceList"
> 
>  repeat for each line f in field "FlagList"
> 
>     repeat for each line l in field "SourceList"
> 
>        repeat for each item i in l
>            if i contains f then set the foregroundColor of f to "red"
>        end repeat
> 
>     end repeat
> 
>  end repeat
> 
>   else     
>      --no file was selected, or cancel was pressed
>      beep
>      end if
> end mouseUp
> 
> I think I'm making a basic error, so grateful for any guidance. 
> Best, 
> Keith..
> _______________________________________________
> 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