LeftUntil, RightUntil Functions

Requires: GfaWinx.lg32

Purpose

Return left or right portion of string upto or including a specific string.

Syntax

str$ = LeftUntil(src$, find$[, fInclude? = False][, ignorecase? = False])
str$ = RightUntil(src$, find$[, fInclude? = False][, ignorecase? = False])

find$, src$: string
fInclude?, ignorecase?: boolean

Description

These functions search a string (from the left or right end, depending upon which function is used) for a specific character or group of characters and return that portion of the string upto (or including if fInclude is set to True) the specified character(s); if the specified character or characters is not found, then the whole of the source string is returned

By default, the character search is case sensitive; this can be changed by passing True as the fourth parameter.

Example

Local a$ = "GFABasic with gfawinx", b$ = "nx"

Debug LeftUntil(a$, "i")                // "GFABas" (upto string, case sensitive)

Debug LeftUntil(a$, "i", True)          // "GFABasi" (upto string, case sensitive)

Debug LeftUntil(a$, "AW", True)         // "GFABasic with gfawinx" [string not found] (upto string, case sensitive)

Debug LeftUntil(a$, "AW", True, True)   // "GFABasic with gfaw" (including string, ignore case)

Debug RightUntil(a$, "nx")              // Empty String (upto string, case sensitive)

Debug RightUntil(a$, "nx", True)        // "nx" (including string, case sensitive)

Debug RightUntil(a$, "G", True)         // "GFABasic with gfawinx" (including string, case sensitive)

Debug RightUntil(a$, "G", True, True)   // "gfawinx" (including string, ignore case)

Debug.Show

See Also

InStr, Left$, Right$

{Created by Sjouke Hamstra; Last updated: 18/12/2022 by James Gaite}