isdigit(3f) - [M_strings:COMPARE] returns .true. if character is a
digit (0,1,...,9) and .false. otherwise
(LICENSE:PD)
elemental function isdigit(onechar)
character,intent(in) :: onechar
logical :: isdigit
isdigit(3f) returns .true. if character is a digit (0,1,...,9)
and .false. otherwise
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
John S. Urban
Public Domain
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character, | intent(in) | :: | ch |
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