比较两个版本号 [英] Comparing two version numbers
本文介绍了比较两个版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何比较两个版本号字符串?
例如:3.1.1和3.1.2.5.4
现在我需要知道3.1.2.5.4是否高于3.1.1,但我不知道如何做到这一点。
任何人都可以帮助我?
提前感谢!
解决方案
示例代码:
NSString * v1 = @3.1.1
NSString * v2 = @3.1.2.5.4;
if([v1 compare:v2 options:NSNumericSearch] == NSOrderedDescending){
NSLog(@%@大于%@,v1,v2)
}
从比较和排序字符串。 p>
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!
解决方案
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.
这篇关于比较两个版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文