Re: counting w*rds
Re: counting w*rds
- Subject: Re: counting w*rds
- From: Michelle Steiner <email@hidden>
- Date: Tue, 22 May 2001 17:58:58 -0700
On 5/21/01 10:03 PM, Ehsan Saffari <email@hidden> wrote:
>
and on a similar note, how to count the occurances of a substring in a
>
string?
Well, someone answered your first question; here's an answer to the
second.
--Michelle
set StringtoCount to "substring1 anotherstring1 substring2 anotherstring2
substring3 anotherstring3 substring4"
set substring to "substring"
set finalCount to countSubstring(StringtoCount, substring, 0)
on countSubstring(target, findthis, counter)
if findthis is in target then
set counter to counter + 1
set len to length of findthis
set targetstart to offset of findthis in target
if targetstart is 1 then
set newtarget to text (len + 1) through -1 of target
else
if targetstart + len is less than or equal to length of target then
set newtarget to (text 1 through (targetstart - 1)) of target & text
(targetstart + len) through -1 of target
else
set newtarget to ""
end if
end if
else
return counter
end if
countSubstring(newtarget, findthis, counter)
end countSubstring
----------------------------------------------------------------------
| Michelle Steiner | We're not human beings having a spiritual |
| | experience. We're spiritual beings |
| email@hidden | having a human experience. |
----------------------------------------------------------------------