compact(3f) - [M_strings:WHITESPACE] converts contiguous whitespace to a single character (or nothing) (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
License
function compact(STR,CHAR) result (OUTSTR)
character(len=*),intent(in) :: STR character(len=*),intent(in),optional :: CHAR character(len=len(str)) :: OUTSTR
COMPACT(3f) converts multiple spaces, tabs and control characters (called "whitespace") to a single character or nothing. Leading whitespace is removed.
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.
OUTSTR string of same length as input string but with all contiguous whitespace reduced to a single space and leading whitespace removed
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_compactExpected output
>This is a test >Thisisatest >This:is:a:test >AAAAAAAAAAAA
John S. Urban
Public Domain
Nemo Release 3.1 | compact (3m_strings) | January 10, 2025 |