版本比较

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

# * 版本比较
   # * @param version1
   # * @param version2
   # * @return
   # * -1: version1小于version2
   # * 1:  version1大于version2
   # * 0:  version1等于version2
  def versionCompare version1,version2
    strArr1 = version1.split('.')
    strArr2 = version2.split('.')
    maxLen = strArr1.length > strArr2.length ? strArr1.length : strArr2.length
    result = 0
    for i in 0..maxLen
      begin
        sa = strArr1[i].to_i
      rescue
        sa = 0
      end
      begin
        sb = strArr2[i].to_i
      rescue
        sa = 0
      end
      if sa > sb
        result = 1
      elsif sa < sb
        result = -1
      else
        result = 0
      end
      if result != 0
        break;
      end
    end 
    return result
  end