Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

5.11. Exercises

  1. Modify the program from this chapter that enumerated words to log the number of special characters in the text. For purposes of this program, consider any characters that are not part of a word as a special character. (Hint: You can subtract the numbers of characters used by all the words in the text from the total number of characters in the text to get your answer.)

  2. Extend the quotation program from this chapter by adding some quotes of your own.

  3. Write an AppleScript program to take a path represented as a string and log the last component. If the path ends in a : character, display the component before the colon. So for, example, the path

    Macintosh HD:Users:stevekochan:mysrc:scripts:ch05:enum1.scpt

    should cause the program to log the string "enum1.scpt", and the path

    Macintosh HD:Users:stevekochan:mysrc:

    should cause it to log "mysrc".

  4. Predict the output logged from the following program. Then type and run the program to verify your answers.

    set myText to "Don't get from-to mixed up with thru!"
    log text from word 1 to word 2 of myText
    log text from character 5 to character 10 of myText
    log text from character ((count myText) - 4) to end of myText
    set n to offset of "from" in myText
    log text from character 1 to character (n - 1) of myText
    log characters 1 through (n - 1) of myText

  5. Write a program to count the number of occurrences of the word the in some text. Be sure to ignore case.

  6. Extend the alarm clock program to accept abbreviations "secs", for seconds, "min", "minute", and "mins" for minutes, and "hr", "hour", and "hrs" for hours.

  7. Write a program that effectively removes a string from inside another string. For example, if the variable myText is defined as follows:

    set myText to "There's got to be some way out of here!"

    and the variable removeString is defined like this:

    set removeString to "got to be "

    you want to produce a string that contains the contents of myText with removeString effectively removed from it, that is, the following string:

    "There's some way out of here!"

  8. Predict the output logged by the following program:

    considering case and hyphens
       log "ye-s" = "YES"
    end considering
    ignoring diacriticals
        log "première" = "premiere"
    end ignoring
    considering case but ignoring punctuation and white space
        log "1., 2., 3." = "123"
        log "It's as easy as A, B, C" = "its as easy as abc."
    end ignoring


You are currently reading a PREVIEW of this book.


Get instant access to over $1 million worth of books and videos.


Start a Free Trial

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint