Manual Reference Pages  - join (3m_unicode)

NAME

JOIN(3f) - [M_unicode:EDITING] append CHARACTER variable array into a single CHARACTER variable with specified separator (LICENSE:MIT)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

impure function join(str,sep,clip) result (string)

     type(unicode_type),intent(in)          :: str(:)
     type(unicode_type),intent(in),optional :: sep
     logical,intent(in),optional            :: clip
     type(unicode_type),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 variables to be joined
SEP separator string to place between each variable. defaults to a null string.
CLIP option to trim each element of STR of trailing and leading 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_unicode,  only : join, ut=>unicode_type, ch=>character, assignment(=)
   !use M_unicode, only : write(formatted)
   implicit none
   character(len=*),parameter    :: w=’((g0,/,g0))’
   !character(len=*),parameter   :: v=’((g0,/,DT))’
   character(len=20),allocatable :: proverb(:)
   type(ut),allocatable          :: s(:)
   type(ut),allocatable          :: sep
     !
     proverb=[ character(len=13) :: &
       & ’ United’       ,&
       & ’  we’          ,&
       & ’   stand,’     ,&
       & ’    divided’   ,&
       & ’     we fall.’ ]
     !
     if(allocated(s))deallocate(s)
     allocate(s(size(proverb))) ! avoid GNU Fortran (GCC) 16.0.0 bug
     s=proverb
     write(*,w) ’SIMPLE JOIN:         ’, ch( join(s)                )
     write(*,w) ’JOIN WITH SEPARATOR: ’, ch( join(s,sep=ut(’ ’))    )
     write(*,w) ’CUSTOM SEPARATOR:    ’, ch( join(s,sep=ut(’<-->’)) )
     write(*,w) ’NO TRIMMING:         ’, ch( join(s,clip=.false.)   )
     !
     sep=ut()
     write(*,w) ’SIMPLE JOIN:         ’, ch(sep%join(s) )
     sep=’ ’
     write(*,w) ’JOIN WITH SEPARATOR: ’, ch(sep%join(s) )
     sep=’<-->’
     write(*,w) ’CUSTOM SEPARATOR:    ’, ch(sep%join(s) )
     sep=’’
     write(*,w) ’NO TRIMMING:         ’, ch(sep%join(s,clip=.false.) )
   end program demo_join

Results:

  > SIMPLE JOIN:
  > Unitedwestand,dividedwe fall.
  > JOIN WITH SEPARATOR:
  > United we stand, divided we fall.
  > CUSTOM SEPARATOR:
  > United==>we==>stand,==>divided==>we fall.
  > NO TRIMMING:
  >  United         we             stand,         divided        we fall.
  > SIMPLE JOIN:
  > Unitedwestand,dividedwe fall.
  > JOIN WITH SEPARATOR:
  > United we stand, divided we fall.
  > CUSTOM SEPARATOR:
  > United==>we==>stand,==>divided==>we fall.
  > NO TRIMMING:
  >  United         we             stand,         divided        we fall.

AUTHOR

John S. Urban

LICENSE

    MIT