Get number of occurrences of one string in another

Ken Ray kray at sonsothunder.com
Thu Feb 23 13:10:36 EST 2012


On Feb 22, 2012, at 9:46 PM, Bob Sneidar wrote:

> only works for single characters. 
> 
> function substringCount pString, pChunk
>  replace pString with cr & pString & cr in pChunk
>  filter pChunk with pString
>  return the number of lines of pChunk
> end substringCount

Here's one that works if you only have 1 character you're searching for:


   split tString by tChar
   put (the number of elements of tString) - 1 into tNumOccurrences


Just offering another way to do it…

:D

Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/	




More information about the use-livecode mailing list