Name
begin[s] with
Syntax
set mybool to ("zoology" starts with "zoo") -- returns true
Synonyms
start[s] with
Return value
boolean
; true
or
false
Description
The operands for these operators must be strings or lists. If the
operand to the left contains the operand to the right, then the
expression returns true
. If the operands do not
evaluate to the same class, then AppleScript attempts to coerce the
right operand to the class of the left operand. You can combine
strings and lists in these statements. For example:
set mybool to ( {"string", "twine"} starts with "string" )
returns true
, because AppleScript coerces the
right operand to a single-item string
("{"string"}")
before it makes the starts with
comparison. This operator and its synonym are designed
to compare operands that are either both strings or both lists,
however. This operator and its sibling ends
with
are very handy for identifying portions of
strings within larger strings. For example, if you prefixed the
characters “db_” to all of your
database files, then you could distinguish those files by using the
begins
with
operator, as in the
following example.
Examples
tell application "Finder" get count of (files whose name begins with "db_") end tell
Get AppleScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.