Before (String function)

From m204wiki
Revision as of 20:33, 23 April 2014 by Alan (talk | contribs)
Jump to navigation Jump to search

Part of string before a substring (String class)

[Introduced in Model 204 7.5]


Before operates on a string and returns the portion of that string prior to the user-specified delimiter. To get the portion of the string after a delimiter, use the After string method.

Syntax

%outString = string:Before( substring, [Start= number])

Syntax terms

%outString A string or longstring variable. if a string is specified it must be long enough to hold the resulting parsed string. If a string is defined shorter than needed to hold the result, a request canceling error occurs.
string A string or longstring variable that holds the string to be parsed.
substring A string or longstring that holds the separator character or characters on which parsing occurs.
Start number
The starting point for parsing. The default value is 1, indicating the beginning of the string. This is a name-optional argument and cannot be 0. If a value larger than the string is specified, the method always returns a null string.

Usage notes

If a starting value is entered, the %outString is the content of the string beginning at the specified start point and ending at either the character before the first delimiter encountered after the start point, or at the end of the string. See the examples. The delimiter string is not a list of individual delimiters, but a single delimiter which may be multiple characters. In other words, if your delimiter is 'ok', the method looks for occurrences of those two lower-case letters and returns a value before said occurrence, This method is always case-sensitive.

Examples

The following request prints

I am the Eggman

begin %x is string len 64 initial('I am the Eggman! I am the Walrus! Koo Koo Kachoo!') printText {%x:before('!')} end

The following request prints

Eggman!

begin %x is string len 64 initial('I am the Eggman! I am the Walrus! Koo Koo Kachoo!') printText {%x:before('!',start=10)} end

The following prints each blank-delimited word, one at a time.

begin %x is string len 64 initial('I am the Eggman! I am the Walrus! Koo Koo Kachoo!') repeat while %x:length print %x:before(' ') %x = %x:after(' ') end repeat end

See also

The After string method.