ADJUSTL(3) - [CHARACTER:WHITESPACE] Left-justified 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 = sample string character(len=:),allocatable :: astr integer :: lengthResults:! basic use write(*,(a,"[",a,"]")) original: ,str str=adjustl(str) write(*,(a,"[",a,"]")) adjusted: ,str
! a fixed-length string can be printed ! trimmed using trim(3) or len_trim(3) write(*,(a,"[",a,"]")) trimmed: ,trim(str) length=len_trim(str) write(*,(a,"[",a,"]")) substring:,str(:length)
! note an allocatable string stays the same length too ! and is not trimmed by just an adjustl(3) call. astr= allocatable string write(*,(a,"[",a,"]")) original:,astr astr = adjustl(astr) write(*,(a,"[",a,"]")) adjusted:,astr ! trim(3) can be used to change the length astr = trim(astr) write(*,(a,"[",a,"]")) trimmed: ,astr
end program demo_adjustl
> original: [ sample string ] > adjusted: [sample string ] > trimmed: [sample string] > substring:[sample string] > original:[ allocatable string ] > adjusted:[allocatable string ] > trimmed: [allocatable string]
Fortran 95
ADJUSTR(3), TRIM(3)
Fortran intrinsic descriptions (license: MIT) @urbanjost
Nemo Release 3.1 | adjustl (3fortran) | November 02, 2024 |