Page 2 of 2

Re: Searching for all instances of a string

Posted: Tue Aug 23, 2022 11:28 pm
by rkriesel
stoavio wrote: Wed Jul 17, 2013 12:22 am ... I guess I tend to assume there are easier ways to do things most of the time but in this case, the method for this particular manipulation wasn't quite as straight-forward as I assumed it would be.
---
Since this old thread is current again, let's give its subject some fresh consideration.

Here's a newer way to count occurrences of a substring like "APPROVAL   NO"

Code: Select all

function countSubstrings pString, pSubstring
   set the lineDelimiter to pSubstring
   return number of lines in pString - 1
end countSubstrings
Here's a way to retrieve the "BEGIN" blocks that contain the substring.

Code: Select all

function blocksWithSubstring pString, pBlockDelimiter, pSubstring
   set the lineDelimiter to pBlockDelimiter
   filter pString with "*" & pSubstring & "*"
   -- now replace the block delimiters that were just filtered out:
   repeat for each line tLine in pString
      get it & pBlockDelimiter & tLine & cr
   end repeat
   return it
end blocksWithSubstring
The OP's last activity was over three years ago. Comment, anyone?

-- Dick