ADJUSTL(3) - [CHARACTER:WHITESPACE] Left-justify a string
result = adjustl(string)
elemental character(len=len(string),kind=KIND) function adjustl(string)character(len=*,kind=KIND),intent(in) :: string
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
ADJUSTL(3) will left-justify a string by removing leading spaces. Spaces are inserted at the end of the string as needed.
o STRING : the string to left-justify
A copy of STRING where leading spaces are removed and the same number of spaces are inserted on the end of STRING.
Sample program:
program demo_adjustl implicit none character(len=20) :: str character(len=:),allocatable :: astr character(len=*),parameter :: au= (a,"[",a,"]") integer :: istart, iendResults:! 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
> original: [ sample string ] > adjusted: [sample string ] > trimmed: [sample string] > substring:[sample string] > trimmed: [sample string]
Fortran 95
ADJUSTR(3), TRIM(3)
Fortran intrinsic descriptions (license: MIT) @urbanjost
