help files
Z505 | PasWiki | FUQ | Search | Main Docs | API Guide



[Overview][Constants][Types][Classes][Procedures and functions][Variables] Reference for unit 'sysutils' (#rtl)

StrToInt

Convert a string to an integer value.

Declaration

Source position: sysstrh.inc line 110

function StrToInt(

  const s: String

):Integer;

Description

StrToInt will convert the string Sto an integer. If the string contains invalid characters or has an invalid format, then an EConvertError is raised.

To be successfully converted, a string can contain a combination of numerical characters, possibly preceded by a minus sign (-). Spaces are not allowed.

Errors

In case of error, an EConvertError is raised.

See also

IntToStr

  

Convert an integer value to a decimal string.

StrToIntDef

  

Convert a string to an integer value, with a default value.

Example

Program Example82;

{$mode objfpc}

{ This program demonstrates the StrToInt function }

Uses sysutils;

Begin
  Writeln (StrToInt('1234'));
  Writeln (StrToInt('-1234'));
  Writeln (StrToInt('0'));
  Try
    Writeln (StrToInt('12345678901234567890'));
  except
    On E : EConvertError do
      Writeln ('Invalid number encountered');
  end;
End.

Notes

 No notes exist for this page yet. 





lufdoc, Powtils, fpc, freepascal, delphi, kylix, c/c++, mysql, cgi web framework docs, Z505