Return true if all characters in the string are digits.
type(string) :: astring
logical :: test_passed(2)
astring = ' -1212112.3 '
test_passed(1) = astring%is_digit().eqv..false.
astring = '12121123'
test_passed(2) = astring%is_digit().eqv..true.
print '(L1)', all(test_passed)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self |
The string. |
Result of the test.
elemental function is_digit(self) !< Return true if all characters in the string are digits. !< !<```fortran !< type(string) :: astring !< logical :: test_passed(2) !< astring = ' -1212112.3 ' !< test_passed(1) = astring%is_digit().eqv..false. !< astring = '12121123' !< test_passed(2) = astring%is_digit().eqv..true. !< print '(L1)', all(test_passed) !<``` !=> T <<< class(string), intent(in) :: self !< The string. logical :: is_digit !< Result of the test. integer :: c !< Character counter. is_digit = .false. if (allocated(self%raw)) then do c=1, len(self%raw) select case (self%raw(c:c)) case ('0':'9') is_digit = .true. case default is_digit = .false. exit end select enddo endif endfunction is_digit