Re: Newbie. How do I count "i"?
Re: Newbie. How do I count "i"?
- Subject: Re: Newbie. How do I count "i"?
- From: "Marc K. Myers" <email@hidden>
- Date: Sat, 26 Jan 2002 15:12:09 -0500
- Organization: [very little]
>
Date: Sat, 26 Jan 2002 11:47:30 +0100
>
Subject: Newbie. How do I count "i"?
>
From: Steen <email@hidden>
>
To: <email@hidden>
>
>
Hello.
>
>
I hope someone can tell me how I can count every "i" in z.
>
I have been looking everywhere to find the solution.
>
>
set z to "ideas how to do this?"
>
count every character = "i" in z
>
>
When I do this I get an error.
>
>
Any help with this at will be greatly appreciated.
set z to "Now is the time for all good men to come to the aid of the party!"
cntChar(z, "i")
on cntChar(theText, theChar)
try
set theText to (theText as text)
on error
display dialog "That's not text!"
return
end try
set {od, AppleScript's text item delimiters} to [optn-L]
{AppleScript's text item delimiters, {theChar}}
set charCnt to (count (text items of theText)) - 1
set AppleScript's text item delimiters to od
return charCnt
end cntChar
Note that "[optn-L]" stands in for AppleScript's continuation character.
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[1/26/02 3:11:00 PM]