Manual Reference Pages  - isdigit (3m_strings)

NAME

isdigit(3f) - [M_strings:COMPARE] returns .true. if character is a digit (0,1,...,9) and .false. otherwise (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

elemental function isdigit(onechar)

    character(len=*),intent(in) :: onechar
    logical              :: isdigit

DESCRIPTION

isdigit(3f) returns .true. if character is a digit (0,1,...,9) and .false. otherwise

OPTIONS

onechar
  character to test

RETURNS

isdigit
  Returns true logical value if character is a "digit"
( an ASCII-7
  character from the set {0,1,..,9}). That is, from CHAR(48) to CHAR(57) inclusive. If a multi-byte string was input .false. is returned if any character is not a digit. A null string returns .false.

EXAMPLES

Sample Program:

   program demo_isdigit

use M_strings, only : isdigit, isspace, switch implicit none character(len=10),allocatable :: string(:) character(len=1),allocatable :: chars(:) character(len=*),parameter :: g=’(*(g0,1x))’ integer :: i

string=[& & ’1 2 3 4 5 ’ ,& & ’letters ’ ,& & ’1234567890’ ,& & ’both 8787 ’ ]

! if string is nothing but digits and whitespace return .true.

print g,’using ISDIGIT(3) and ISSPACE(3):’ do i=1,size(string) ! convert to array of single characters chars=switch(string(i)) print g, ’For string[’,string(i),’]’, & & all( isdigit(chars) .or. isspace(chars) ) enddo

! ALTERNATIVE using VERIFY(3) ! the Fortran intrinsic function VERIFY(3) returns a position just ! not a logical like C, which can be useful for complex comparisons print g,’using VERIFY(3):’ do i=1,size(string) print g, ’For string[’,string(i),’]’, & & verify(string(i), "01234567890 ") == 0 enddo

end program demo_isdigit

Expected output:

   > using ISDIGIT(3) and ISSPACE(3):
   > For string[ 1 2 3 4 5  ] T
   > For string[ letters    ] F
   > For string[ 1234567890 ] T
   > For string[ both 8787  ] F
   > using VERIFY(3):
   > For string[ 1 2 3 4 5  ] T
   > For string[ letters    ] F
   > For string[ 1234567890 ] T
   > For string[ both 8787  ] F

AUTHOR

John S. Urban

LICENSE

Public Domain