标签:string http com split 代码 count tps turn 软件版本
7.版本号比较(字符串比较)
int CompareVersion(QString strVer1, QString strVer2) { if ( !strVer1.compare( strVer2 ) ) { return 0; } QStringList list1 = strVer1.split( "." ); QStringList list2 = strVer2.split( "." ); int iTotal1 = list1.count(); int iTotal2 = list2.count(); int iTotal=iTotal1>iTotal2?iTotal2:iTotal1; int iValue1 = 0, iValue2 = 0; bool ibOK1 = false, ibOK2 = false; for ( int iNum = 0; iNum < iTotal; ++iNum ) { iValue1 = list1[iNum].toInt( &ibOK1 ); if (!ibOK1) { iValue1=0; } iValue2 = list2[iNum].toInt( &ibOK2 ); if (!ibOK2) { iValue2=0; } if (iValue1==iValue2) { continue; } else if ( iValue1 < iValue2 ) { return -1; } else { return 1; } } return iTotal1<iTotal2?-1:1; }
测试:
CompareVersion("16.01.19", "16.01.19") //return 0; CompareVersion("16.01.19", "16.01.18") //return 1; CompareVersion("16.01.18", "16.01.19") //return -1;
https://www.cnblogs.com/sz-leez/p/6537004.html
标签:string http com split 代码 count tps turn 软件版本
原文地址:https://www.cnblogs.com/findumars/p/9189641.html