Manual Reference Pages - squeeze (3m_strings)
NAME
squeeze(3f) - [M_strings:EDITING] delete adjacent duplicate occurrences
of a character from a string
(LICENSE:PD)
CONTENTS
Synopsis
Description
Options
Returns
Examples
Author
License
SYNOPSIS
function squeeze(STR,CHAR) result (OUTSTR)
character(len=*),intent(in) :: STR
character(len=1),intent(in),optional :: CHAR
character(len=len(str)) :: OUTSTR
DESCRIPTION
squeeze(3f) reduces adjacent duplicates of the specified character
to a single character
OPTIONS
|
STR |
input string in which to reduce adjacent duplicate characters
to a single character
|
|
CHAR |
The character to remove adjacent duplicates of
|
|
RETURNS
|
OUTSTR |
string with all contiguous adjacent occurrences of CHAR removed
|
|
EXAMPLES
Sample Program:
program demo_squeeze
use M_strings, only : squeeze
implicit none
call printme( , )
call printme(1111 1111 111 111 1117777888,[1,7,X] )
call printme( Mary had a lllittllle lllamb,l)
contains
impure elemental subroutine printme(str,chr)
character(len=*),intent(in) :: str
character(len=1),intent(in) :: chr
character(len=:),allocatable :: answer
write(*,(a))repeat(=,42)
write(*,("IN: ",g0))str
answer=squeeze(str,chr)
write(*,("OUT: ",g0))answer
write(*,("LENS: ",*(g0,1x)))"from",len(str),"to",len(answer), &
& "for a change of",len(str)-len(answer)
write(*,("CHAR: ",g0))chr
end subroutine printme
end program demo_squeeze
Expected output
> ==========================================
> IN:
> OUT:
> LENS: from 0 to 0 for a change of 0
> CHAR:
> ==========================================
> IN: 1111 1111 111 111 1117777888
> OUT: 1 1 1 1 17777888
> LENS: from 32 to 20 for a change of 12
> CHAR: 1
> ==========================================
> IN: 1111 1111 111 111 1117777888
> OUT: 1111 1111 111 111 1117888
> LENS: from 32 to 29 for a change of 3
> CHAR: 7
> ==========================================
> IN: 1111 1111 111 111 1117777888
> OUT: 1111 1111 111 111 1117777888
> LENS: from 32 to 32 for a change of 0
> CHAR: X
> ==========================================
> IN: Mary had a lllittllle lllamb
> OUT: Mary had a little lamb
> LENS: from 29 to 23 for a change of 6
> CHAR: l
AUTHOR
John S. Urban
LICENSE
Public Domain