isdigit Function

public elemental function isdigit(ch) result(res)

NAME

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

SYNOPSIS

elemental function isdigit(onechar)

 character,intent(in) :: onechar
 logical              :: isdigit

DESCRIPTION

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

EXAMPLES

Sample Program:

 program demo_isdigit
 use M_strings, only : isdigit, isspace, switch
 implicit none
 character(len=10),allocatable :: string(:)
 integer                       :: i
    string=[&
    & '1 2 3 4 5 ' ,&
    & 'letters   ' ,&
    & '1234567890' ,&
    & 'both 8787 ' ]
    ! if string is nothing but digits and whitespace return .true.
    do i=1,size(string)
       write(*,'(a)',advance='no')'For string['//string(i)//']'
       write(*,*) &
        & all(isdigit(switch(string(i))).or.&
        & isspace(switch(string(i))))
    enddo
 end program demo_isdigit

Expected output:

    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

Arguments

Type IntentOptional Attributes Name
character, intent(in) :: ch

Return Value logical


Contents

Source Code


Source Code

elemental function isdigit(ch) result(res)

! ident_69="@(#) M_strings isdigit(3f) Returns .true. if ch is a digit (0-9) and .false. otherwise"

character,intent(in) :: ch
logical              :: res
   select case(ch)
   case('0':'9')
     res=.true.
   case default
     res=.false.
   end select
end function isdigit