Converting a text string to an integer with an optional sign.

 

Syntax

function StrToInt(sSt: string): integer;

 

Parameter

Type

Value

sValue

string

string that you need to convert to a real number.

 

Function result

Integer that corresponds to the transmitted string. If the conversion fails, the function returns 0.


var
  iA, iB, iC, iD, iE, iSum: integer;
begin
  iA := 32;
  iB := StrToInt('100');    // string '100' converts to integer 100
  iC := StrToInt('  -12');  // leading spaces are ignored
  iD := StrToInt('$1E');    // hexadecimal values begin with '$'
  iE := StrToInt('-0x1E');  // ... or with '0x'
  iSum := iA + iB + iC + iD + iE;  // add these integers together
  mLogScript(IntToStr(iA), '');
  mLogScript(IntToStr(iB), '');
  mLogScript(IntToStr(iC), '');
  mLogScript(IntToStr(iD), '');
  mLogScript(IntToStr(iE), '');
  mLogScript(IntToStr(iSum), '');
end.


 Script work result

[20:47:46] (Log "test"): 32

[20:47:46] (Log "test"): 100

[20:47:46] (Log "test"): -12

[20:47:46] (Log "test"): 30

[20:47:46] (Log "test"): -30

[20:47:46] (Log "test"): 120

 

See also

IntToStr

mLogScript