• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: When to use text VS text item
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When to use text VS text item


  • Subject: Re: When to use text VS text item
  • From: "Nigel Garvey" <email@hidden>
  • Date: Mon, 8 Sep 2008 14:36:47 +0100

Joe wrote on Fri, 5 Sep 2008 13:51:22 -0700:

>I have both seen examples and tried constructions like the following.
>
>text 10 thru text -2
>
>text 10 thru text item -2

The first of these compiles down to 'text 10 thru -2', which, when
applied to text, returns the text from the tenth character to the second-
to-last character of the original. Alternatively, when applied to a list,
it returns all the text values in that list from the tenth to the next-
to-last.

Your second example can only be applied to text and returns the text from
the tenth character of an original to the second-to-last text item. The
term 'text item' shouldn't be confused with 'text'. A 'text' item is any
text that occurs between (but not including) two instances of the current
value of 'AppleScript's text item delimiters'.

  set t to "The Adventures of Aaron the Aardvark"
  text 10 thru -2 of t
  --> "tures of Aaron the Aardvar"

  set AppleScript's text item delimiters to "ar"
  text 10 thru text item -2 of t
  --> "tures of Aaron the Aardv"
  -- (text item -1 is "k", text item -2 is "dv")

>While trying to explore the differences between these two statements,
>I came across a lengthy discussion in the archives concerning the
>differences. The discussion starts here:
>
>http://lists.apple.com/archives/applescript-users/2002/Feb/msg01162.html
>
>I am wondering, given that AppleScript has changed a lot since then,
>if the arguments presented remain valid today in AppleScript 2?

Basically, yes. One thing that is different is the interpretation of
overlapping boundary parameters, which is not the same for Unicode text
as for strings:

  set t to "'Antidisestablishmentarianism' is a long word"
  text 5 thru word 1 of t
  --> "idisestablishmentarianism"

  set t to "'Antidisestablishmentarianism' is a long word" as Unicode text
  text 5 thru word 1 of t
  --> "Antidisestablishmentarianism"

AppleScript 2 uses Unicode exclusively, so that part of the original post
no longer applies.

>Reading posts to this list from the last few months suggests this may
>no longer be true. Almost everyone uses the former

Standards have gone down if they do.  ;)

> while no one seems
>to use the latter.

It depends what they're trying to achieve.

>Is this difference any longer important?

Yes.


NG

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: Safari: make new tab
  • Next by Date: Automating certain actions in Firefox
  • Previous by thread: Re: When to use text VS text item
  • Next by thread: re: strange behaviour of QT Player 7.5 when setting window bounds
  • Index(es):
    • Date
    • Thread