Re: Searching for all instances of a string
Posted: Tue Aug 23, 2022 11:28 pm
Since this old thread is current again, let's give its subject some fresh consideration.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.
---
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 countSubstringsCode: 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-- Dick