pascal

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


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

Thank you.


Solution

  • The is procedure Val:

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

    This procedure operate on decimal and real numbers.

    Parmeters:

    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