mergeChars Function

public pure function mergeChars(str, c) result(res)

Merge characters in a string if they are contiguous.

Syntax

 s = mergeChars(str, c)

Where:

  • str: String to search inside for contiguous duplicated characters.
  • substr: Character to search for contiguous duplications.

String with the selected character contiguous duplications removed.

Example

The following program removes contiguos characters:

 PROGRAM mergeCharsExample
    USE FU_Strings, ONLY: mergeChars
    IMPLICIT NONE
    CHARACTER(LEN=:), ALLOCATABLE :: text
    CHARACTER(LEN=:), ALLOCATABLE :: modified_text
    text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, &
       &sed do eiusmod tempor incididunt ut labore et dolore magna al&
       &iqua. Ut enim ad minim veniam, quis nostrud exercitation ulla&
       &mco laboris nisi ut aliquip ex ea commodo consequat. Duis aut&
       &e irure dolor in reprehenderit in voluptate velit esse cillum&
       & dolore eu fugiat nulla pariatur. Excepteur sint occaecat cup&
       &idatat non proident, sunt in culpa qui officia deserunt molli&
       &t anim id est                       laborum."
     modified_text = mergeChars(text, ' ')
     WRITE(*,*) modified_text
 END PROGRAM mergeCharsExample

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

String to search inside for contiguous duplicated characters.

character(len=*), intent(in) :: c

Character to search for contiguous duplications.

Return Value character(len=:), ALLOCATABLE

String with the selected character contiguous duplications removed.


Contents