Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string to integer conversion in Pascal, How to do it?

Tags:

pascal

How to convert a number printed in a string into integer?

Thank you.

like image 671
Aftershock Avatar asked Nov 05 '10 10:11

Aftershock


3 Answers

The is procedure Val:

procedure Val(S; var V; var Code: Integer);

This procedure operate on decimal and real numbers.

Parmeters:

  • S char sequence; for proper conversion it has to contain ‘+’, ‘-‘, ‘,’, ’.’, ’0’..’9’.
  • V The result of conversion. If result going to be an Integer then S can't contain ‘,’, ’.’.
  • C Return the position of the character from S, that interrupt the conversion.

Use cases:

Var Value :Integer;

Val('1234', Value, Code);  // Value = 1234, Code = 0
Val('1.234', Value, Code); // Value = 0, Code = 2
Val('abcd', Value, Code);  // Value = 0, Code = 1
like image 173
Damian Leszczyński - Vash Avatar answered Oct 16 '22 14:10

Damian Leszczyński - Vash


You can use Val function.

Example:

var
   sNum: String;
   iNum: Integer;
   code: Integer;

begin
   s := '101';
   Val(s, iNum, code); 
end.
like image 1
pyCoder Avatar answered Oct 16 '22 13:10

pyCoder


You want Val().

like image 1
Ignacio Vazquez-Abrams Avatar answered Oct 16 '22 12:10

Ignacio Vazquez-Abrams