Manual Reference Pages  - join (3m_strings)

NAME

join(3f) - [M_strings:EDITING] append CHARACTER variable array into a single CHARACTER variable with specified separator (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

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

DESCRIPTION

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.

OPTIONS

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.

RETURNS

STRING CHARACTER variable composed of all of the elements of STR() appended together with the optional separator SEP placed between the elements.

EXAMPLES

Sample program:

    program demo_join
    use M_strings, only: join
    implicit none
    character(len=:),allocatable  :: s(:)
      s=[character(len=10) :: ’United’,’we’,’stand,’, &
      & ’divided’,’we fall.’]

write(*,’(a)’) ’SIMPLE JOIN: ’,& join(s) write(*,’(a)’) ’SIMPLE JOIN WITH SEPARATOR: ’,& join(s,sep=’ ’) write(*,’(a)’) ’CUSTOM SEPARATOR: ’,& join(s,sep=’==>’) write(*,’(a)’) ’LEFT AND RIGHT AND SEPARATOR: ’,& join(s,sep=’;’,left=’[’,right=’]’) write(*,’(a)’) ’NO TRIMMING: ’,& join(s,trm=.false.) write(*,’(a)’) ’LEFT AND RIGHT: ’,& join(s,left=’[’,right=’]’) write(*,’(a)’) ’START,END AND EVERYTHING: ’,& join(s,trm=.false.,sep=’,’,start=’[’,end=’]’,left=’"’,right=’"’)

write(*,’(a)’) ’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_join

Results:

 > 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.  |          |
 > #----------#----------#----------#

AUTHOR

John S. Urban

LICENSE

Public Domain


Nemo Release 3.1 join (3m_strings) July 20, 2024
Generated by manServer 1.08 from a419f342-9285-4a56-9c68-51124826dc5b using man macros.