5.6. Words, Characters, and Paragraphs

You saw that a character string is simply a sequence of characters. AppleScript allows you to perform some basic operations with strings. For example, you've already seen how to concatenate two strings and how to count the number of characters in a string. In this section, you see how you can extract characters, words, and paragraphs from character strings. First, examine the following table to see how AppleScript defines these terms.

ClassMeaningExamples
characterA single character from a string"a"

"!"

"="

"9"
wordA contiguous sequence of letters, numbers, commas (between digits), periods (before digits), currency symbols, percent signs, apostrophes (witin sequences of letter or numbers) and hyphens.AppleScript

3.14159

$318,000

re-animated

1.34e+10
paragraphA sequence of characters up to the end of the string or a return or linefeed character, whichever occurs first"para1\rpara2\rpara3"
text itemA sequence of characters delimited by the characters specified by text item delimiters; using the default setting, a text item is a single character from a stringlast text item of fileName

You can see from the table that a word is not just a sequence of letters. It includes numbers, currency amounts, and in general, any sequence of characters that would be logically grouped together.

A paragraph is a sequence of characters ending in a return or linefeed character. If you're used to working with a word processing application like MS Word, this definition ...

Get Beginning AppleScript® 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.