Manual Reference Pages  - adjustl (3fortran)

NAME

ADJUSTL(3) - [CHARACTER:WHITESPACE] Left-justify a string

SYNOPSIS

result = adjustl(string)

       elemental character(len=len(string),kind=KIND) function adjustl(string)

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

CHARACTERISTICS

o STRING is a character variable of any supported kind
o The return value is a character variable of the same kind and length as STRING

DESCRIPTION

ADJUSTL(3) will left-justify a string by removing leading spaces. Spaces are inserted at the end of the string as needed.

OPTIONS

o STRING : the string to left-justify

RESULT

A copy of STRING where leading spaces are removed and the same number of spaces are inserted on the end of STRING.

EXAMPLES

Sample program:

    program demo_adjustl
    implicit none
    character(len=20)            :: str
    character(len=:),allocatable :: astr
    character(len=*),parameter   :: au= ’(a,"[",a,"]")’
    integer :: istart, iend

! basic use str=’ sample string ’ write(*,au) ’original: ’,str

! note the allocated string stays the same length ! and is not trimmed by just an adjustl(3) call. astr=adjustl(str) write(*,au) ’adjusted: ’,astr

! a fixed-length string can be printed cropped ! combining adjustl(3) with trim(3) write(*,au) ’trimmed: ’,trim(adjustl(str))

! or even printed without adjusting the string a ! cropped substring can be printed iend=len_trim(str) istart= verify(str, ’ ’) ! first non‐blank character write(*,au) ’substring:’,str(istart:iend)

! to generate an actually trimmed allocated variable astr = trim(adjustl(str)) write(*,au) ’trimmed: ’,astr

end program demo_adjustl

Results:

       > original: [   sample string    ]
       > adjusted: [sample string       ]
       > trimmed:  [sample string]
       > substring:[sample string]
       > trimmed:  [sample string]

STANDARD

Fortran 95

SEE ALSO

ADJUSTR(3), TRIM(3)

Fortran intrinsic descriptions (license: MIT) @urbanjost