ParseLines (String function)

From m204wiki
Jump to navigation Jump to search

Parse delimited string, creating new Stringlist (String class)


ParseLines creates a Stringlist whose items are substrings of a given string. The substrings are determined by a user-identified delimiter string.

Syntax

%sl = string:ParseLines[( [delims], [StripTrailingNull= boolean])]

Syntax terms


%sl A Stringlist object to contain as its items the identified substrings of the method object, string.
string The string to be parsed to provide the content of the %sl Stringlist.
delims A string that is a list of one or more line delimiters that determine the substrings that become %sl Stringlist items. If specified, the first character in the delimiter list is the separator character for the delimiter list itself, and the remainder are the delimiters to be used to separate string into substrings.

If this optional argument is not specified, the delimiter list that applies is X'0D', X'25', and X'0D25' (which are the EBCDIC carriage-return, line-feed, and carriage-return/line-feed characters respectively). These should handle any line-end delimited data from an ASCII host that is been translated to ASCII.

StripTrailingNull This name required argument is a boolean value that indicates whether a trailing null line should be stripped. StripTrailingNull is an optional argument that defaults to true, which results in a trailing null line being stripped.

Usage notes

  • The CreateLines function performs the inverse operation; that is, it creates a string by concatenating the items in a Stringlist with separator strings between the items.

Examples

If Longstring %ls is 'every,good,boy,does,fine', and %sl is a Stringlist, and you specify:

%sl = %ls:parselines(' ,') %sl:print

The result is:

every good boy does fine

See also