After (String function)

From m204wiki
Revision as of 20:02, 3 September 2015 by ELowell (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Part of string after a substring (String class)

[Introduced in Model 204 7.5]

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

Syntax

%outString = string:After( 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 the defined string is 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 variable that holds the separator character or characters on which parsing occurs.
Start A number that is the starting point for parsing. The default value is 1, indicating the beginning of the string. This is a name allowed argument, and it cannot be 0. If you specify a value larger than the string, After returns a null string.

Usage notes

  • If a starting value is specified, %outString is the string content that begins after the first occurrence of the delimiter string encountered after the specified start value, and that ends at the end of the string. 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, After looks for occurrences of those two lowercase letters and returns a value after the first such occurrence that follows the start value.
  • This method is always case-sensitive.

Examples

The following string (note the initial blanks) is the result of the request displayed below it:

  I am the Walrus! Koo Koo Kachoo!

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

The following string is the result of the request displayed below it:

  Koo Koo Kachoo!

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

The following request 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