Manual Reference Pages  - len_trim (3fortran)

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 intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 len_trim (3fortran) November 02, 2024
Generated by manServer 1.08 from 99e31e03-0c21-4b4d-a995-2f51aaba4488 using man macros.