C Library Functions  - len_trim (3)

NAME

LEN_TRIM(3) - [CHARACTER:WHITESPACE] Character length without trailing blank characters

SYNOPSIS

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

CHARACTERISTICS

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.

DESCRIPTION

LEN_TRIM(3) returns the length of a character string, ignoring any trailing blanks.

OPTIONS

o STRING : The input string whose length is to be measured.
o KIND : Indicates the kind parameter of the result.

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.

EXAMPLES

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)

! 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

Results:

         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

STANDARD

Fortran 95 . KIND argument added with Fortran 2003.

SEE ALSO

Functions that perform operations on character strings, return lengths of arguments, and search for certain arguments:
o ELEMENTAL: ADJUSTL(3), ADJUSTR(3), INDEX(3), SCAN(3), VERIFY(3)
o NONELEMENTAL: REPEAT(3), LEN(3), TRIM(3)
fortran-lang intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 len_trim (3) July 22, 2023
Generated by manServer 1.08 from ce4605e1-3ccd-48c2-a6b8-10ff3f6f0e9d using man macros.