December 2004
Beginner
600 pages
13h 42m
English
-- Counting special characters
set theText to "AppleScript is a flexible language that allows you to easily work
with elements in strings and lists."
set wordChars to 0
-- sequence through each word in the string
repeat with theWord in (get every word in theText)
set wordChars to wordChars + count theWord
end repeat
-- log the Answer set specialChars to (count theText) - wordChars log "There are " & specialChars & " special characters in the text."
No answer shown.
-- Get the last ocmponent in a path
set myPath to "Macintosh HD:Users:steve:mysrc:scripts:ch05:enum1.scpt"
-- save the old delimiters and change to a :
set saveTextItemDelimiters to text item delimiters
set text item delimiters to ":"
-- get the last text item; if it's null, get the one before it
set component to text item −1 of myPath
if component = "" then
set component to text item −2 of myPath
end if
log component
-- restore the old delimiters
set textItemDelimiters to saveTextItemDelimiters
Here's the output from the Event Log:
(*Don't get*)
(*t get *)
(*thru!*)
tell current application
offset of "from" in "Don't get from-to mixed up with thru!"
11
(*Don't get *)
(*D, o, n, ', t, , g, e, t, *)
end tell
-- count the number of occurrence of a word set searchWord to "the" set someText to "The word \"the\" is the most common word in the English language" set wordCount ...
Read now
Unlock full access