Manual Reference Pages  - adjustl (3fortran)

NAME

ADJUSTL(3) - [CHARACTER:WHITESPACE] Left-justified 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 = ’   sample string’
    character(len=:),allocatable :: astr
    integer :: length

! 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(3f) or len_trim(3f) 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(3f) call. astr=’ allocatable string ’ write(*,’(a,"[",a,"]")’) ’original:’,astr astr = adjustl(astr) write(*,’(a,"[",a,"]")’) ’adjusted:’,astr ! trim(3f) can be used to change the length astr = trim(astr) write(*,’(a,"[",a,"]")’) ’trimmed: ’,astr

end program demo_adjustl

Results:

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

STANDARD

Fortran 95

SEE ALSO

ADJUSTR(3), TRIM(3)

fortran-lang intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 adjustl (3fortran) April 28, 2024
Generated by manServer 1.08 from e9da5206-6ed9-4a85-808d-760f3dd2625e using man macros.