crop Function

public function crop(strin) result(strout)

NAME

crop(3f) - [M_strings:WHITESPACE] trim leading and trailing blanks
           and control characters from a string
(LICENSE:PD)

SYNOPSIS

function crop(strin) result (strout)

 character(len=*),intent(in)  :: strin
 character(len=:),allocatable :: strout

DESCRIPTION

All control characters throughout the string are replaced with spaces
and leading and trailing spaces are trimmed from the resulting string.
Tabs are expanded assuming a stop every eight characters.

OPTIONS

strin   input string to trim leading and trailing space and control
        characters from

RETURNS

strout  cropped version of input string

EXAMPLE

Sample program:

program demo_crop
use M_strings, only: crop
implicit none
character(len=20) ::  untrimmed = '   ABCDEFG abcdefg  '
   write(*,*) 'untrimmed string=[',untrimmed,']'
   write(*,*) 'cropped string=[',crop(untrimmed),']'
end program demo_crop

Expected output

  untrimmed string=[   ABCDEFG abcdefg                      ]
  cropped string=[ABCDEFG abcdefg]

AUTHOR

John S. Urban

LICENSE

Public Domain

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: strin

Return Value character(len=:), allocatable


Contents

Source Code


Source Code

function crop(strin) result (strout)

! ident_16="@(#) M_strings crop(3f) replace control characters with whitespace and trim leading and trailings spaces from resulting string"

character(len=*),intent(in)  :: strin
character(len=:),allocatable :: strout
   strout=trim(adjustl(noesc(dilate(strin))))
end function crop