Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Fortran

Idiom #137 Check if string contains only digits

Set the boolean b to true if the string s contains only characters in the range '0'..'9', false otherwise.

b = .true.
do i=1, len(s)
  if (s(i:i) < '0' .or. s(i:i) > '9') then
    b = .false.
    exit
  end if
end do
B := (for all Char of S => Char in '0' .. '9');

New implementation...
< >
programming-idioms.org