Substr.StrToInt Method

function StrToInt(const S: Substring): Integer; overload; inline;

Converts S to an Integer by ToInteger's rules.

#NameTypeDescription
1SSubstring

Returns: Integer

Remarks:

A text that is no Integer raises EConvertError: '<text>' is not a valid integer value.

Examples

A value, and a refused text.

uses Substr, System.SysUtils;

procedure Example;
var Raised: Boolean;
begin
    Assert(StrToInt(Substring('-12')) = -12);
    Raised := False;
    try
        Assert(StrToInt(Substring('x')) = 0);
    except
        on E: EConvertError do Raised := E.Message = '''x'' is not a valid integer value';
    end;
    Assert(Raised);
end;