Manual Reference Pages  - trim (3fortran)

NAME

TRIM(3) - [CHARACTER:WHITESPACE] Remove trailing blank characters from a string

SYNOPSIS

result = trim(string)

         character(len=:,kind=KIND) function trim(string)

character(len=*,kind=KIND),intent(in) :: string

CHARACTERISTICS

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.

DESCRIPTION

TRIM(3) removes trailing blank characters from a string.

OPTIONS

o STRING : A string to trim

RESULT

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.

EXAMPLES

Sample program:

    program demo_trim
    implicit none
    character(len=:), allocatable :: str, strs(:)
    character(len=*),parameter :: brackets=’( *("[",a,"]":,1x) )’
    integer :: i

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

Results:

        > [   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]

STANDARD

Fortran 95

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: LEN_TRIM(3), LEN(3), REPEAT(3), TRIM(3)
fortran-lang intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 trim (3fortran) April 28, 2024
Generated by manServer 1.08 from a51e99d5-7d3a-4a32-885d-2ec75030ebd4 using man macros.