The OOC Library supplies various procedures to convert between string values
and numeric representation. These include procedures for conversions of
both INTEGER
and LONGINT
variables to and from string format.
As module IntConv is low-level, the average application programmer will most likely find module IntStr more interesting and useful.
Module ConvTypes declares common types, and appropriate related constants, which are used in the various string conversion modules.
ConvResults
are used to express the status of attempts
to format a string via the string-to-number conversion procedures. The
following constants are defined for its value:
ScanClass
are used to classify input to finite
state scanners. The following constants are defined for its value:
ScanState
is the type of lexical scanning control procedures. It has
a single field of PROCEDURE
type:
PROCEDURE (ch: CHAR; VAR cl: ScanClass; VAR st: ScanState)
Module IntConv provides low-level integer/string conversions.
ConvResults
is a local equivalent to ConvTypes.ConvResults
.
This type has associated constants with the same meanings as in module
ConvTypes (see section Module ConvTypes)
Constants strAllRight
, strOutOfRange
, strWrongFormat
,
and strEmpty
are all valid values for ConvResults
.
(inputCh: CHAR; VAR chClass: ConvTypes.ScanClass; VAR nextState: ConvTypes.ScanState)
Please note: ScanInt
is used by procedures FormatInt
and ValueInt
.
(str: ARRAY OF CHAR): ConvResults
LONGINT
.
(str: ARRAY OF CHAR): LONGINT
(int: LONGINT): INTEGER
IntStr.IntToStr(int,str)
(see section Module IntStr)
(): BOOLEAN
TRUE
if the current process is in the
exceptional execution state because of the raising of the IntConv exception;
otherwise, it returns FALSE
.
Module IntStr provides integer-number/ string conversions for numbers in the form of signed whole numbers (see section Syntax of Text Tokens).
ConvResults
is a local equivalent to ConvTypes.ConvResults
.
This type has associated constants with the same meanings as in module
ConvTypes (see section Module ConvTypes)
Constants strAllRight
, strOutOfRange
, strWrongFormat
,
and strEmpty
are all valid values for ConvResults
.
(str: ARRAY OF CHAR; VAR int: LONGINT; VAR res: ConvResults)
StrToInt
ignores any leading spaces in str. If the subsequent characters in
str are in the format of a signed whole number, it assigns a
corresponding value to int.
res indicates the result of the conversion based on the format of str.
Example:
VAR stringVar: ARRAY 32 OF CHAR; intVar: LONGINT; res: IntStr.ConvResults; stringVar := " 54321"; IntStr.StrToInt(stringVar, intVar, res); => intVar = 54321, res = strAllRight stringVar := "12345678901234567890"; IntStr.StrToInt(stringVar, intVar, res); => intVar is undefined, res = strOutOfRange stringVar := "54321.0"; IntStr.StrToInt(stringVar, intVar, res); => intVar is undefined, res = strWrongFormat stringVar := " "; IntStr.StrToInt(stringVar, intVar, res); => intVar is undefined, res = strEmpty
(int: LONGINT; VAR str: ARRAY OF CHAR)
Example:
VAR stringVar: ARRAY 6 OF CHAR; intVar: LONGINT; intVar := 54321; IntStr.IntToStr(intVar, stringVar); => stringVar = "54321" intVar := 1234567890; IntStr.IntToStr(intVar, stringVar); => stringVar = "12345"
Go to the first, previous, next, last section, table of contents.