Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing two version numbers

How can I compare two Version number strings?

For example: 3.1.1 and 3.1.2.5.4

Now I need to find out if 3.1.2.5.4 is higher than 3.1.1 but I don't know how to do this. Can anybody help me?

Thanks in advance!

like image 494
AmiiQo Avatar asked Sep 03 '13 13:09

AmiiQo


1 Answers

Sample Code :

NSString* v1 = @"3.1.1";
NSString* v2 = @"3.1.2.5.4";

if ([v1 compare:v2 options:NSNumericSearch] == NSOrderedDescending) {
    NSLog(@"%@ is greater than %@",v1,v2);
}

From the Apple Documentation for Comparing and sorting strings.

like image 80
Bhavin Avatar answered Sep 27 '22 18:09

Bhavin