{替换字符串}
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;

 

posted on 2015-02-16 11:32  rilizj  阅读(277)  评论(0编辑  收藏  举报