RosettaCodeData/Task/Count-occurrences-of-a-substring/AppleScript/count-occurrences-of-a-substring-2.applescript
2023-07-01 13:44:08 -04:00

10 lines
395 B
AppleScript

on countSubstring(theString, theSubstring)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to theSubstring
set substringCount to (count theString's text items) - 1
set AppleScript's text item delimiters to astid
return substringCount
end countSubstring
{countSubstring("the three truths", "th"), countSubstring("ababababab", "abab")}