• 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: Manipulate the last item in a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Manipulate the last item in a string


  • Subject: Re: Manipulate the last item in a string
  • From: Malcolm Fitzgerald <email@hidden>
  • Date: Mon, 19 Jun 2006 07:41:52 +1000


On 17/06/2006, at 11:53 PM, kai wrote:


On 17 Jun 2006, at 13:04, Marine Themes wrote:

Using applescript with Filemaker I can make a string of found image record names such as this:

"1234.jpg, 5678.jpg, 4444.jpg, 5555.jpg, 9876.jpg, 6969.jpg."

What I want to do is delete the last comma and insert an "&" into the string to make:

"1234.jpg, 5678.jpg, 4444.jpg, 5555.jpg, 9876.jpg & 6969.jpg."

I assume that I use text item deliminators but not sure how as there are multiple ", " in the string and record names will vary with each use of the script. Any suggestions?

You can count back from the end of a list using negative indices, Clive:


--------

set t to "1234.jpg, 5678.jpg, 4444.jpg, 5555.jpg, 9876.jpg, 6969.jpg."
set text item delimiters to ", "
set t to t's text 1 thru text item -2 & " & " & t's text item -1
set text item delimiters to {""}
t --> "1234.jpg, 5678.jpg, 4444.jpg, 5555.jpg, 9876.jpg & 6969.jpg."

--------

I like reverse of and rest of! No one else has shown this technique so I'll include it for completeness:


set s to "1234.jpg, 5678.jpg, 4444.jpg, 5555.jpg, 9876.jpg, 6969.jpg."
set text item delimiters to ", "
set t to reverse of (text items of s)
return "" & (reverse of (rest of t)) & " & " & item 1 of t

--> "1234.jpg, 5678.jpg, 4444.jpg, 5555.jpg, 9876.jpg & 6969.jpg."


Malcolm


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Manipulate the last item in a string (From: Marine Themes <email@hidden>)
 >Re: Manipulate the last item in a string (From: kai <email@hidden>)

  • Prev by Date: Re: Dot files
  • Next by Date: Re: Dot files
  • Previous by thread: Re: Manipulate the last item in a string
  • Next by thread: Re: Manipulate the last item in a string
  • Index(es):
    • Date
    • Thread