clip(3f) - [M_strings:WHITESPACE] trim leading and trailing blanks from a string
(LICENSE:PD)
function clip(strin) result (strout)
character(len=*),intent(in) :: strin
character(len=:),allocatable :: strout
leading and trailing spaces are trimmed from the resulting string.
strin input string to trim leading and trailing space characters from
strout clipped version of input string
Sample program:
program demo_clip
use M_strings, only: clip
implicit none
character(len=20) :: untrimmed = ' ABCDEFG abcdefg '
write(*,*) 'untrimmed string=[',untrimmed,']'
write(*,*) 'clipped string=[',clip(untrimmed),']'
end program demo_clip
Expected output
untrimmed string=[ ABCDEFG abcdefg ]
clipped string=[ABCDEFG abcdefg]
John S. Urban
Public Domain
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | string |
function clip(string) result(lopped)
! ident_17="@(#) M_strings clip(3f) trim leading and trailings spaces from resulting string"
logical,parameter :: T=.true.,F=.false.
character(len=*),intent(in) :: string
character(len=:),allocatable :: lopped
integer :: ends(2)
ends=verify( string, " ", [F,T] )
if(ends(1) == 0)then
lopped=""
else
lopped=string(ends(1):ends(2))
endif
end function clip