LEN_TRIM(3) - [CHARACTER:WHITESPACE] Character length without trailing blank characters
result = len_trim(string [,kind])
elemental integer(kind=KIND) function len_trim(string,KIND)character(len=*),intent(in) :: string integer(kind=KIND),intent(in),optional :: KIND
o STRING is of type character o KIND is a scalar integer constant expression specifying the kind of the returned value. o The return value is of type integer and of kind KIND. If KIND is absent, the return value is of default integer kind.
LEN_TRIM(3) returns the length of a character string, ignoring any trailing blanks.
o STRING : The input string whose length is to be measured. o KIND : Indicates the kind parameter of the result.
The result equals the number of characters remaining after any trailing blanks in STRING are removed.
If the input argument is of zero length or all blanks the result is zero.
Sample program
program demo_len_trim implicit none character(len=:),allocatable :: string integer :: i ! basic usage string=" how long is this string? " write(*,*) string write(*,*)UNTRIMMED LENGTH=,len(string) write(*,*)TRIMMED LENGTH=,len_trim(string)Results:! print string, then print substring of string string=xxxxx write(*,*)string,string,string i=len_trim(string) write(*,*)string(:i),string(:i),string(:i) ! ! elemental example ELE:block ! an array of strings may be used character(len=:),allocatable :: tablet(:) tablet=[character(len=256) :: & & how long is this string? ,& & and this one?] write(*,*)UNTRIMMED LENGTH= ,len(tablet) write(*,*)TRIMMED LENGTH= ,len_trim(tablet) write(*,*)SUM TRIMMED LENGTH=,sum(len_trim(tablet)) endblock ELE ! end program demo_len_trim
> how long is this string? > UNTRIMMED LENGTH= 30 > TRIMMED LENGTH= 25 > xxxxx xxxxx xxxxx > xxxxxxxxxxxxxxx > UNTRIMMED LENGTH= 256 > TRIMMED LENGTH= 25 13 > SUM TRIMMED LENGTH= 38
Fortran 95 . KIND argument added with Fortran 2003.
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: REPEAT(3), LEN(3), TRIM(3)
Nemo Release 3.1 | len_trim (3fortran) | November 02, 2024 |