extractBefore
Extracts the text that comes before a marker or a position.
Category: Language Fundamentals > Data Types
Syntax
newStr = extractBefore(str, pat)
Returns what precedes the first occurrence of pat.
newStr = extractBefore(str, pos)
Returns the characters before position pos.
Description
The marker is excluded from the result. It is the mirror image of extractAfter; together they split a string around a separator without using regexp or split.
Input arguments
str- Text to search.
pat- Marker text or
pattern. Only the first match counts. pos- Positive integer: the position up to (and excluding) which characters are kept.
Output arguments
newStr- The leading part of the text. If
patis not found the result is a missing string.
Example
Text before a marker
extractBefore("abc=def=ghi", "=")
extractBefore("abcdef", 4)
Output
ans = "abc"
ans = "abc"
See also
extractAfter extractBetween extract eraseBetween insertBefore