Operating System - OpenVMS
cancel
Showing results for
Did you mean:

SOLVED
Go to solution

## Checking a String symbol for numerics

Have any of you folks had the occasion to check a symbol of type STRING for all numerics? I need to do that. Using F\$INTEGER returns a value of zero, but zero is a valid value in the data that I'm checking.

4 REPLIES
Honored Contributor

## Re: Checking a String symbol for numerics

How close does F\$TYPE() come?

HELP LEXICALS F\$TYPE

alp \$ x = 123
alp \$ wso f\$type( x)
INTEGER

alp \$ x = "123"
alp \$ wso f\$type( x)
INTEGER

alp \$ x = "1o3"
alp \$ wso f\$type( x)
STRING
Honored Contributor

## Re: Checking a String symbol for numerics

You may also specify the radix, e.g.
\$ A="ABC"
\$ Write Sys\$output F\$Type(A)
STRING
\$ A="%XABC"
\$ Write SyS\$Output F\$Type(A)
INTEGER

regards kALLE
Honored Contributor
Solution

## Re: Checking a String symbol for numerics

Craig,

since you specify that you are starting with a STRING symbol, you can just examine each character in turn and check for a numeric. With a bit of work, you can also allow for negative numbers, leading/trailing spaces etc.

Here is a simplistic sample

\$check_for_numeric: SUBROUTINE
\$!
\$! Check a supplied string for all numeric
\$! sets \$STATUS on exit
\$! 1 = numeric
\$! 2 = false
\$! usage CALL CHECK_FOR_NUMERIC string_to_test
\$ inp_string = p1
\$ len_inp = f\$length(inp_string)
\$ inp_sub = 0
\$char_loop:
\$ test_char = f\$extract(inp_sub,1,inp_string)
\$ if test_char .lts. "0" -
.or. test_char .gts. "9"
\$ then
\$ exit 2
\$ endif
\$ inp_sub = inp_sub + 1
\$ if inp_sub .lt. len_inp
\$ then
\$ goto char_loop
\$ endif
\$ exit 1
\$ENDSUBROUTINE

Duncan