join(3f) - [M_strings:EDITING] append CHARACTER variable array into a single CHARACTER variable with specified separator (LICENSE:PD)
Synopsis
Description
Options
Result
Example
Author
License
pure function join(str,sep,trm,left,right) 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=:),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 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=:),allocatable :: s(:) character(len=:),allocatable :: out integer :: i s=[character(len=10) :: United, we, stand,, divided, we fall.] out=join(s) write(*,(a)) out write(*,(a)) join(s,trm=.false.) write(*,(a)) (join(s,trm=.false.,sep=|),i=1,3) write(*,(a)) join(s,sep=<>) write(*,(a)) join(s,sep=;,left=[,right=]) write(*,(a)) join(s,left=[,right=]) write(*,(a)) join(s,left=>>) end program demo_joinExpected output:
United we stand, divided we fall. United we stand, divided we fall. United | we | stand, | divided | we fall. | United | we | stand, | divided | we fall. | United | we | stand, | divided | we fall. | United<> we<> stand,<> divided<> we fall.<> [United];[ we];[ stand,];[ divided];[ we fall.]; [United][ we][ stand,][ divided][ we fall.] >>United>> we>> stand,>> divided>> we fall.
John S. Urban
Public Domain
join (3) | July 05, 2020 |