TRIM(3) - [CHARACTER:WHITESPACE] Remove trailing blank characters from a string
result = trim(string)
character(len=:,kind=KIND) function trim(string)character(len=*,kind=KIND),intent(in) :: string
o KIND can be any kind supported for the character type. o The result has the same type and kind as the input argument STRING.
TRIM(3) removes trailing blank characters from a string.
o STRING : A string to trim
The result is the same as STRING except trailing blanks are removed.
If STRING is composed entirely of blanks or has zero length, the result has zero length.
Sample program:
program demo_trim implicit none character(len=:), allocatable :: str, strs(:) character(len=*),parameter :: brackets=( *("[",a,"]":,1x) ) integer :: iResults:str= trailing print brackets, str,trim(str) ! trims it
str= leading print brackets, str,trim(str) ! no effect
str= print brackets, str,trim(str) ! becomes zero length print *, len(str), len(trim( ))
! array elements are all the same length, so you often ! want to print them strs=[character(len=10) :: "Z"," a b c","ABC",""]
write(*,*)untrimmed: ! everything prints as ten characters; nice for neat columns print brackets, (strs(i), i=1,size(strs)) print brackets, (strs(i), i=size(strs),1,-1) write(*,*)trimmed: ! everything prints trimmed print brackets, (trim(strs(i)), i=1,size(strs)) print brackets, (trim(strs(i)), i=size(strs),1,-1)
end program demo_trim
> [ trailing ] [ trailing] > [ leading] [ leading] > [ ] [] > 12 0 > untrimmed: > [Z ] [ a b c ] [ABC ] [ ] > [ ] [ABC ] [ a b c ] [Z ] > trimmed: > [Z] [ a b c] [ABC] [] > [] [ABC] [ a b c] [Z]
Fortran 95
Functions that perform operations on character strings, return lengths of arguments, and search for certain arguments:
Fortran intrinsic descriptions (license: MIT) @urbanjost
o ELEMENTAL: ADJUSTL(3), ADJUSTR(3), INDEX(3), SCAN(3), VERIFY(3) o NONELEMENTAL: LEN_TRIM(3), LEN(3), REPEAT(3), TRIM(3)
Nemo Release 3.1 | trim (3fortran) | November 02, 2024 |