parsereal
parsereal |
Purpose
Convert a text into a real.
Synopsis
function parsereal(txt:text,start:integer):real
function parsereal(txt:text):real
function parsereal(txt:text,pctx:parsectx):real
function parsereal(txt:text,ta:textarea):real
Arguments
txt
|
A
text object
|
pctx
|
A parser context
|
ta
|
A text area object
|
start
|
Starting position in the text
|
Return value
The real represented by the string.
Example
The following:
t:=text("a123.4b") writeln(parsereal(t,2)) writeln(getparam("sys_endparse"))
produces this output:
123.4 7
Further information
1. The parsing begins at the specified starting position and stops as soon as an invalid character is found or when the end of the text is reached.
- Standard (initial two) versions: if start is not provided then the value of the control parameter sys_endparse is used as starting position; the location where parsing stops is stored in the parameter sys_endparse.
- Version using a parser context: the information contained in the parser context is used instead of the global parameters (see Section The type parsectx); the context property endparse indicates the starting position and is updated with the location where parsing stops.
- Version using a textarea object: the routine uses the start property of the object (see Section The type textarea) as the starting position but it does not store the position where parsing stops, in particular it does not modify the parameter sys_endparse.
2. If the string starts with the sequence
"0x" or
"OX" an hexadecimal representation of a floating point value will be expected. This representation is of the form
"[+/-]0xh.hhhp[+/-]ddd" where
'h' are hexadecimal digits and
'd' decimal digits.
3. In case of error (no valid character found or overflow) the system status is set with a non-zero value (see
getsysstat) and, depending on the situation, 0,
MAX_REAL or
-MAX_REAL is returned.
Related topics
Module