eraseBetween

Deletes the text lying between two markers or two positions.

Category: Language Fundamentals > Data Types

Syntax

newStr = eraseBetween(str, startPat, endPat)

Deletes what is between the first startPat and the following endPat; the markers stay.

newStr = eraseBetween(str, startPos, endPos)

Deletes the characters from position startPos to endPos.

newStr = eraseBetween(___, 'Boundaries', 'inclusive')

Also deletes the markers themselves.

Description

With text markers, the first match of startPat is found, then the first endPat after it, and what lies between them is deleted. By default the markers are kept, so eraseBetween("[x]", "[", "]") leaves "[]".

With numeric positions the range is always inclusive on both ends.

Input arguments

startPat, endPat
Text markers that delimit the part to delete.
startPos, endPos
Positive integers giving the first and last character to delete.
'Boundaries'
'exclusive' (default) keeps the markers; 'inclusive' removes them.

Output arguments

newStr
Text of the same type as str with the selected part removed.

Example

Markers and positions

eraseBetween("Hello [x] world", "[", "]")
eraseBetween("Hello [x] world", "[", "]", "Boundaries", "inclusive")
eraseBetween("abcdef", 2, 4)
Output
ans = "Hello [] world"
ans = "Hello [] world"
ans = "aef"

See also

erase extractBetween insertAfter insertBefore extractAfter