Delphi or INNO 版本号比较方法 版本差

时间:2015-02-16 12:54:56   收藏:0   阅读:284
{替换字符串}
function StringReplace(const S, OldPattern, NewPattern: string): string;
var
  SearchStr, Patt, NewStr: string;
  Offset: Integer;
begin
  SearchStr := S;
  Patt := OldPattern;
  NewStr := S;
  Result := ‘‘;
  while SearchStr <> ‘‘ do
  begin
    Offset :=Pos(Patt, SearchStr);
    if Offset = 0 then
    begin
      Result := Result + NewStr;
      Break;
    end;
    Result := Result + Copy(NewStr, 1, Offset - 1) + NewPattern;
    NewStr := Copy(NewStr, Offset + Length(OldPattern), MaxInt);
    SearchStr := Copy(SearchStr, Offset + Length(Patt), MaxInt);
  end;
end;

//版本号比较{返回版本差}
function CompareVersion(New, Old: string): Integer;
var
  iNew,iOld:Integer;
begin
  Result := -1;
  iNew := StrToIntDef(StringReplace(New,.,‘‘),-1);
  if iNew = -1 then exit;
  iOld := StrToIntDef(StringReplace(Old,.,‘‘),-1);
  if iOld = -1 then exit;
  Result := iNew - iOld;
end;

 

原文:http://www.cnblogs.com/bkclover/p/4293918.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!