Merge characters in a string if they are contiguous.
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.
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
Type | Intent | Optional | 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. |
String with the selected character contiguous duplications removed.