我想澄清一下 Fortran 处理字符串中“空”字符的方式。让我们假设我们有这种情况:
program main
implicit none
test('AB')
end program
在哪里
function test(name)
implicit none
character(10) :: name
character(3) :: cutname
write(*,*) '-'//name//'-' ! Gives output "-AB -"
! Space has then been added at the end
cutname(1:3) = name(1:3)
write(*,*) '1-'//cutname//'-' ! Gives output "-AB -"
! It seems there is a space then at the end
! of cutname
write(*,*) (cutname(1:2) == 'AB') ! Gives output T (true)
write(*,*) (cutname(3:3) == ' ') ! Gives output F (false)
write(*,*) (cutname == 'AB ') ! Gives output F (false)
end function
我很好奇在这种情况下发生了什么。提前致谢。