Mark A. Boyd's

[MBlogo Animation]  mboyd.com  [MBlogo Animation]

findAllChars.dir

[myDirector] [Home]
Type a string to search for in the text & hit [Search]. It will highlight all occurances of the found text and return a list of starting positions with a hit count.

Download findAllChars.dir
Director 7 script. To use with D8 or higher replace all ¬ characters with \.

The Lingo:
(Syntax highlighting provided by David Mennenoh's way cool HTML-ingo utility).


-- Written by Mark A. Boyd
-- No copyright since I've posted variants of this script all over the place.
-- Please send questions/comments/improvements to lingoboyd@mboyd.com

-- 27-Apr-2000 v1.1
-- Modified first repeat loop for indefinite iterations.

on findAllChars whichString, whichMember, whichColor
  
  stringCount = whichString.length - 1
  theText = member(WhichMember).text
  textCount = theText.length
  outList = [#hitPositions:[],#hits:0]
  charColorList = []
  currentOffset = 0
  
  -- Begin Search
  flag = 0
  repeat while not flag
    -- offset() returns only the first position
    firstPos = offset(whichString, theText)
    if firstPos then
      -- get the position of the last char in the search string.
      lastPos = firstPos + stringCount
      
      -- remember position offsets from original, unmodified text.
      newFirstPos = firstPos + currentOffset
      newLastPos = newFirstPos + stringCount
      
      -- add positions to temporary list for coloring.
      -- also used in counting the number of hits.
      charColorList.add([newFirstPos,newLastPos])
      
      -- append positions to the output list.
      outList.hitPositions.append(firstPos+currentOffset)
      
      -- delete up to the last position so that offset()
      -- can find the next position.
      theText = theText.char[lastPos + 1..textCount]
      currentOffset = currentOffset + lastPos
      textCount = theText.length
    else
      -- no more hits from offset()
      flag = 1
    end if
  end repeat
  
  -- Begin highlighting (if color parameter provided)
  if not whichColor.voidP then
    listCount = charColorList.count
    if listCount then
      repeat with i = 1 to listCount
        theChars = charColorList[i]
        member(whichMember).char[theChars[1]..theChars[2]].color = whichColor
      end repeat
    end if
  end if
  
  outList.hits = charColorList.count
  return outList
end


Home