insertBefore

Inserts text right before a marker or a position.

Category: Language Fundamentals > Data Types

Syntax

newStr = insertBefore(str, pat, new)

Inserts new before each occurrence of pat.

newStr = insertBefore(str, pos, new)

Inserts new before character position pos.

Description

It is the mirror image of insertAfter. Only new characters are added; the original text is kept intact. With a marker, the insertion is made before every match.

Input arguments

str
Text to modify.
pat
Marker text or pattern.
pos
Position before which to insert.
new
Text to insert.

Output arguments

newStr
Text with the insertion made.

Example

Inserting before a marker

insertBefore("abcdef", "cd", "XX")
Output
ans = "abXXcdef"

See also

insertAfter extractBefore replace eraseBetween strcat