Extract integer part of a string - Delphi function


function ExtractIntegerPartOfString(const AValue: String; var StrPart: String; var IntPart: Integer): String;
var
  I: Integer;
begin
  Result := '0';
  StrPart := '';
  IntPart := 1;
  for I := length(AValue)-1 downto 0 do
  begin
    if not (Ord(AValue[I]) in [Ord('0')..Ord('9')]) then
    begin
      if Length(AValue)-I > 0 then
      begin
        StrPart := LeftStr(AValue,I);
        try
          IntPart := StrToInt(RightStr(AValue,Length(AValue)-I))+1;
        except
          IntPart := 1;
          StrPart := LeftStr(AValue,I+1);
        end;
        Result := FormatFloat(Copy('000000000000',1,Length(AValue)-I),IntPart);
      end;
      Break;
    end;
  end;
end;

No comments:

Post a Comment