StrToIntDef
Convert a string to an integer value, with a default value.
Declaration
Source position: sysstrh.inc line 143
  function StrToIntDef(const S: string; Default: LongInt) : LongInt;
Description
StrToIntDef will convert a string to an integer. If the string contains invalid characters or has an invalid format, then Default is returned.
To be successfully converted, a string can contain a combination of numerical characters, possibly preceded by a minus sign (-). Spaces are not allowed.
Errors
None.
See also
| Name | Description | 
|---|---|
| IntToStr | Convert an integer value to a decimal string. | 
| StrToInt | Convert a string to an integer value. | 
Example
Program Example82;
{$mode objfpc}
{ This program demonstrates the StrToInt function }
Uses sysutils;
Begin
  Writeln (StrToIntDef('1234',0));
  Writeln (StrToIntDef('-1234',0));
  Writeln (StrToIntDef('0',0));
  Try
    Writeln (StrToIntDef('12345678901234567890',0));
  except
    On E : EConvertError do
      Writeln ('Invalid number encountered');
  end;
End.