[UP]


Manual Reference Pages  - compact (3)

NAME

compact(3f) - [M_strings:WHITESPACE] converts contiguous whitespace to a single character (or nothing) (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

function compact(STR,CHAR) result (OUTSTR)

    character(len=*),intent(in)          :: STR
    character(len=*),intent(in),optional :: CHAR
    character(len=len(str))              :: OUTSTR

DESCRIPTION

COMPACT(3f) converts multiple spaces, tabs and control characters (called "whitespace") to a single character or nothing. Leading whitespace is removed.

OPTIONS

STR input string to reduce or remove whitespace from
CHAR By default the character that replaces adjacent whitespace is a space. If the optional CHAR parameter is supplied it will be used to replace the whitespace. If a null character is supplied for CHAR whitespace is removed.

RETURNS

OUTSTR string of same length as input string but with all contiguous whitespace reduced to a single space and leading whitespace removed

EXAMPLES

Sample Program:

   program demo_compact
    use M_strings, only : compact
    implicit none
    ! produces ’This is a test               ’
    write(*,*)compact(’  This     is      a     test  ’)
    ! produces ’Thisisatest                  ’
    write(*,*)compact(’  This     is      a     test  ’,char=’’)
    ! produces ’This:is:a:test               ’
    write(*,*)compact(’  This     is      a     test  ’,char=’:’)
    ! note CHAR is used to replace the whitespace, but if CHAR is
    ! in the original string it is just copied
    write(*,*)compact(’A  AA    A   AAAAA’,char=’A’)
    ! produces (original A characters are left as-is) ’AAAAAAAAAAAA’
    ! not ’A’
   end program demo_compact

Expected output

>This is a test >Thisisatest >This:is:a:test >AAAAAAAAAAAA

AUTHOR

John S. Urban

LICENSE

Public Domain


compact (3) March 11, 2021
Generated by manServer 1.08 from ef9f1a62-10ae-438f-94ea-51d83f3d9ab4 using man macros.