Searching for all instances of a string

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

rkriesel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 119
Joined: Thu Apr 13, 2006 6:25 pm

Re: Searching for all instances of a string

Post by rkriesel » Tue Aug 23, 2022 11:28 pm

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

Post Reply