017. Character variables are padded with spaces at the end if necessary#
topic: Character variables
Fortran character variables are padded with spaces at the end if necessary.
The //
operator concatenates.
trim
removes trailing spaces.1
character (len=5) :: v = "one"
print *, "'" // v // "'" ! 'one '
print *, "'" // trim(v) // "'" ! 'one'
print *, len(v), len_trim(v) ! 5 3
end
'one '
'one'
5 3
Fortran character variables are padded with spaces at the end if necessary. The // operator concatenates. Trim removes trailing spaces.
— FortranTip (@fortrantip) December 18, 2021
character (len=5) :: v = "one"
print*,"'" // v // "'" ! 'one '
print*,"'" // trim(v) // "'" ! 'one'
print*,len(v),len_trim(v) ! 5 3
end