! This file: http://ftp.aset.psu.edu/pub/ger/fortran/hdk/Deblank.f90 ! subroutine remove_blanks(chr) ! posted by James Giles at comp.lang.fortran on 3 August 2003. implicit none character(*), intent(inout) :: chr integer :: i, j, istart istart = index(chr, " ") if (istart == 0) return ! no blanks in the argument j = istart-1 ! just before the first blank. do i = istart, len(trim(chr)) if (chr(i:i) /= " ") then j = j+1 chr(j:j) = chr(i:i) endif end do if(j < len(chr)) chr(j+1:) = " " ! clear the rest of the string return end subroutine remove_blanks Program DeBlank ! Simple test of subroutine remove_blanks. Character (len=40) line ! read(*,'(A)') line Line = ' abcd efgh ijkl ' call remove_blanks (line) print *, line end Program DeBlank