Re: Newbie: compare version string
Re: Newbie: compare version string
- Subject: Re: Newbie: compare version string
- From: "Clark Cox" <email@hidden>
- Date: Sun, 9 Dec 2007 10:27:11 -0800
On Dec 9, 2007 7:10 AM, Fritz Anderson <email@hidden> wrote:
> On 9 Dec 2007, at 8:43 AM, norio wrote:
>
> > Is there APIs which compare two version strings: like 10.5 is less
> > than 10.5.1 or 10.5 is greater than 10.4.11.
> > Is it OK to use NSString's compare method? Or should I split those
> > strings by period and make scalers from them?
>
> To my knowledge, there is no such API. My practice is to split by '.'
> and compare components. If you're parsing general version strings, be
> aware that some application version numbers have _four_ components,
> even for released products. (The theory being apparently that you need
> to enumerate bug-fix versions of a bug-fix version.) Also, many
> version strings involve build numbers (some of which are not numeric
> -- e.g. 9B18).
>
> Finally, if you find what we used to call an Apple-style version --
> 1.2b9 -- you have to sort by (v/r/null) > b > a > d.
>
> A lexical comparison (-[NSString compare:]) won't work, even without
> fourth versions and stage letters. Consider that 10.4.1 < 10.4.11 <
> 10.4.2.
No, but
[string1 compare: string2 options: NSNumericSearch]
should work.
--
Clark S. Cox III
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden