Number Parsing in Pascal
Our program demonstrates parsing numbers from strings, which is a common task in many applications. Here’s how to do it in Pascal:
In this Pascal program:
We use the
SysUtils
unit, which provides number parsing functions.StrToFloat
is used to parse floating-point numbers.StrToInt64
is used for parsing 64-bit integers. It can also handle hexadecimal numbers when prefixed with ‘$’.StrToQWord
is used for parsing unsigned 64-bit integers.StrToInt
is a convenience function for parsing basic integers.These functions raise an
EConvertError
exception when given invalid input, which we catch and handle in a try-except block.
To run the program, save it as number_parsing.pas
and compile it with a Pascal compiler like Free Pascal:
Note that the exact output format of floating-point numbers may vary depending on your system and compiler settings.
Next, we’ll look at another common parsing task: URLs.