• 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: Text items
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Text items


  • Subject: Re: Text items
  • From: kai <email@hidden>
  • Date: Tue, 16 Jan 2007 21:50:15 +0000


On 16 Jan 2007, at 20:25, Fleisher, Ken wrote:

So besides stripping the ".xxx" extension, I need to strip "_M" if present.
How could I adapt your method to include this? As I said before, right now I
am just looping through every file. It's not necessarily too slow, I just
want to learn how to do it better.

The simplest way to adapt the script would be to introduce a second loop, Ken. This would test for the 2 name endings, "_M." & "." - in that order (longer variant first). Naturally, this doubles up on the iterations - so, for the examples given, the script would loop 4 times: 2 (name ends) * 2 (extensions).


I've added the name end variants to the calling statement, since this might offer some extra flexibility in certain situations.

-------------

to strip_ends of l from e
	set tid to text item delimiters
	set text item delimiters to return
	set l to l as Unicode text
	repeat with d in e
		repeat
			set text item delimiters to d
			if (count l's text items) is 1 then exit repeat
			set text item delimiters to d & paragraph 1 of l's text item -1
			set l to l's text items
			set text item delimiters to ""
			set l to l as Unicode text
		end repeat
	end repeat
	set text item delimiters to tid
	l's paragraphs
end strip_ends

set names1 to {"231-001_M.tif", "231-001.tif", "231-001.jpg", "231-001-a_M.tif", "231-001-a.tif", "231-001-a.jpg"}

set names1 to strip_ends of names1 from {"_M.", "."}

--> {"231-001", "231-001", "231-001", "231-001-a", "231-001-a", "231-001-a"}

-------------

---
kai


_______________________________________________ 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/mailman//archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: Text items
      • From: kai <email@hidden>
References: 
 >Re: Text items (From: "Fleisher, Ken" <email@hidden>)

  • Prev by Date: Re: Text items
  • Next by Date: Re: Text items
  • Previous by thread: Re: Text items
  • Next by thread: Re: Text items
  • Index(es):
    • Date
    • Thread