IntParse Method (RUNTIME)


10.3A

 

The IntParse method parses an input character string and returns a numeric value based on the format of the input characters. This method uses the following format:

 

[label]

{object}.IntParse

[GIVING {return}] USING [*NumericStr=]{numstring}[:

 

 

[*Format=]{format}]

 

Where:

label

Optional. A Program Execution Label.

object

Required. A RUNTIME object.

return

Optional. A Numeric Variable that returns the numeric value as parsed from the input {numstring}

numstring

Required. A Character String Variable or string literal that specifies character string to be parsed. This string is parsed for a format determined by the {format} parameter.

format
Optional. A Numeric Variable or decimal number that specifies a value that identifies the character string format to be parsed.

Flags Affected: EOS, OVER, ZERO

Note the following:

  1. If the {return} value is zero, The ZERO flag is set.

  2. The OVER flag is set if the {return} variable is too small to receive the numeric result.

  3. The EOS flag is always set to FALSE.

  4. The {format} values are described as follows:

  5.  

    Value

    Description

    0

    If the {format} parameter is not specified, this is the default format value used. When the {format} is zero, this method parses the {numstring} as a hexadecimal characters ( 0 to F) if the string starts with '0x'. Otherwise, this method parses the {numstring} as decimal characters ( 0 to 9 ). The parsing stops when the first invalid character as per the format is detected.

    1

    This format only parses the input {numstring} as hexdecimal string formatted as '0xXXXXXXXX'. Example: '0x12abc'

    n < 0

    The return result is zero.

    n > 1

    The return result is zero.

Examples:

 

I1 INTEGER 4

I2 INTEGER 4

I3 INTEGER 4

I4 INTEGER 4

R RUNTIME

.

Test1 INIT "123456"

.

Test2 INIT "0x1aB"

.

Test3 INIT "123x456"

.

Test4 INIT "0xABC"

.

        R.IntParse GIVING I1 USING Test1 //Expect I1=123456

.

        R.IntParse GIVING I2 USING Test2 //Expect I2=427

.

        R.IntParse GIVING I3 USING Test3 //Expect I3=123

.

        R.IntParse GIVING I4 USING Test4, 1 //Expect I4=2740

 

 

See Also: RUNTIME, RUNTIME Methods, Method Syntax

 



PL/B Language Reference HttpStdInSize Method (RUNTIME) IntToString Method (RUNTIME)