• 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: how to do a proper alphabetical sort?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to do a proper alphabetical sort?


  • Subject: Re: how to do a proper alphabetical sort?
  • From: Christopher Nebel <email@hidden>
  • Date: Fri, 9 Mar 2007 09:37:54 -0800

On Mar 8, 2007, at 3:42 PM, Patrik B. wrote:

I am looking for a library or method that does an alphabetical sort?

I need it so that I can write a script that will sort all entries in a
glossary properly in Indesign CS. The script I have currently does not work
properly and sorts the characters by ASCII value so a lower case "a" comes
after a capital "Z" instead of after a capital "A" like it does in a real
dictionary.


Any ideas would be appreciated.

I'm surprised you even hit this problem in the first place -- AppleScript's comparison operators applied to strings will do the right thing [1]. Did you use "ASCII number" as part of your sorting routine? Any textbook sort algorithm will work with minimal adaptation, such as Mr. Pugh's mergesort example. For sufficiently small lists, a sort running in pure AppleScript will outperform 'do shell script "sort"' because of the overhead of calling the latter; on the other hand, the 'do shell script "sort"' method is only five lines long.



--Chris Nebel AppleScript Engineering

[1] Whatever "right" happens to mean for your locale and considering/ ignoring settings. For instance, in English considering case (which is not the default, you'll need a "considering case" block), "A" comes before "a", and both of them come before "B" and "b". Tiger added "considering numeric strings", which makes numbers sort numerically, instead of by their character values. For example:

	"2" < "10" --> false
	considering numeric strings
		"2" < "10" --> true
	end
_______________________________________________
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
References: 
 >how to do a proper alphabetical sort? (From: "Patrik B." <email@hidden>)

  • Prev by Date: Scripting TextEdit and saving a file without user intervention
  • Next by Date: Write defaults
  • Previous by thread: Re: how to do a proper alphabetical sort?
  • Next by thread: Re: how to do a proper alphabetical sort?
  • Index(es):
    • Date
    • Thread