join(3f) - [M_strings:EDITING] append CHARACTER variable array into a single CHARACTER variable with specified separator (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
License
pure function join(str,sep,trm,left,right,start,end) result (string)
character(len=*),intent(in) :: str(:) character(len=*),intent(in),optional :: sep logical,intent(in),optional :: trm character(len=*),intent(in),optional :: right character(len=*),intent(in),optional :: left character(len=*),intent(in),optional :: start character(len=*),intent(in),optional :: end character(len=:),allocatable :: string
JOIN(3f) appends the elements of a CHARACTER array into a single CHARACTER variable, with elements 1 to N joined from left to right. By default each element is trimmed of trailing spaces and the default separator is a null string.
STR(:) array of CHARACTER variables to be joined SEP separator string to place between each variable. defaults to a null string. LEFT string to place at left of each element RIGHT string to place at right of each element START prefix string END suffix string TRM option to trim each element of STR of trailing spaces. Defaults to .TRUE.
STRING CHARACTER variable composed of all of the elements of STR() appended together with the optional separator SEP placed between the elements.
Sample program:
program demo_join use M_strings, only: join implicit none character(len=*),parameter :: w=(/,*(g0,/,g0)) character(len=:),allocatable :: s(:) s=[character(len=10) :: & & United, & & we, & & stand,, & & divided, & & we fall.] write(*,w) SIMPLE JOIN: ,& join(s) write(*,w) SIMPLE JOIN WITH SEPARATOR: ,& join(s,sep= ) write(*,w) CUSTOM SEPARATOR: ,& join(s,sep===>) write(*,w) LEFT AND RIGHT AND SEPARATOR: ,& join(s,sep=;,left=[,right=]) write(*,w) NO TRIMMING: ,& join(s,trm=.false.) write(*,w) LEFT AND RIGHT: ,& join(s,left=[,right=]) write(*,w) START,END AND EVERYTHING: ,& join(s,trm=.false.,sep=,,start=[,end=],left=",right=") write(*,w) TABLE call line() write(*,(a)) join(s(1:3),trm=.false.,sep=|,start=|,end=|) write(*,(a)) join([s(4:5),repeat( ,len(s))],& & trm=.false.,sep=|,start=|,end=|) call line() contains subroutine line() integer :: i write(*,(a)) join([(repeat(-,len(s)),i=1,3)],& & sep=#,start=#,end=#) end subroutine line end program demo_joinResults:
> > SIMPLE JOIN: > Unitedwestand,dividedwe fall. > > SIMPLE JOIN WITH SEPARATOR: > United we stand, divided we fall. > > CUSTOM SEPARATOR: > United==>we==>stand,==>divided==>we fall. > > LEFT AND RIGHT AND SEPARATOR: > [ United];[we];[stand,];[divided];[we fall.] > > NO TRIMMING: > United we stand, divided we fall. > > LEFT AND RIGHT: > [ United][we][stand,][divided][we fall.] > > START,END AND EVERYTHING: > [" United ","we ","stand, ","divided ","we fall. "] > > TABLE > > #----------#----------#----------# > | United |we |stand, | > |divided |we fall. | | > #----------#----------#----------#
John S. Urban
Public Domain
Nemo Release 3.1 | join (3m_strings) | January 10, 2025 |