• 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: Comparing version strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing version strings


  • Subject: Re: Comparing version strings
  • From: "Mark J. Reed" <email@hidden>
  • Date: Thu, 11 Dec 2008 10:58:29 -0500

set v12 to "1.2"
set v125 to "1.2.5"
set v127 to "1.2.7"
set v13 to "1.3"
set match to v125 > v12 (* returns true *)
log match
set match to v127 > v125 (* returns true *)
log match
set match to v13 > v127 (* returns true *)
log match

set v1_10 to "1.10"
set match to v1_10 > v13 (* returns false *)
log match


Try this:

to compareVersions(v1, v2)
    set oldTID to AppleScript's text item delimiters
    set text item delimiters to "."
    set l1 to text items of v1
    set l2 to text items of v2
    set AppleScript's text item deilmiters to oldTID

    repeat with i from 1 to count(l1)
        set n1 to item i of l1 as integer
        set n2 to item i of l2 as integer
        if n1 < n2 then
                 return -1
        else if n1 > n2 then
                return  1
     end if
    end repeat
    return 0
end compareVersions

--
Mark J. Reed <email@hidden>

 _______________________________________________
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

  • Follow-Ups:
    • Re: Comparing version strings
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Finder folder names (From: Luther Fuller <email@hidden>)
 >Re: Finder folder names (From: Luther Fuller <email@hidden>)
 >Re: Finder folder names (From: Tim Mansour <email@hidden>)
 >Re: Finder folder names (From: Luther Fuller <email@hidden>)
 >Dock folder menus (From: Luther Fuller <email@hidden>)
 >Comparing version strings (From: SVV Satyanarayana <email@hidden>)
 >Re: Comparing version strings (From: KOENIG Yvan <email@hidden>)

  • Prev by Date: Re: Code Signing
  • Next by Date: Stack overflow
  • Previous by thread: Re: Comparing version strings
  • Next by thread: Re: Comparing version strings
  • Index(es):
    • Date
    • Thread