ParseLines (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (Automatically generated page update)
 
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Template:String:ParseLines subtitle}}
{{Template:String:ParseLines subtitle}}
<var>ParseLines</var> creates a <var>Stringlist</var> whose items are substrings of a given string. The substrings are determined by a user-identified delimiter string.


==Syntax==
==Syntax==
{{Template:String:ParseLines syntax}}
{{Template:String:ParseLines syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%stringlist</th><td><var>Stringlist</var> object</td></tr>
<tr><th>%sl</th>
<td>A <var>Stringlist</var> object to contain as its items the identified substrings of the method object, <var class="term">string</var>.</td></tr>
 
<tr><th>string</th>
<tr><th>string</th>
<td>string</td></tr>
<td>The string to be parsed to provide the content of the <var class="term">%sl</var> <var>Stringlist</var>.</td></tr>
 
 
<tr><th>delims</th>
<tr><th>delims</th>
<td>string</td></tr>
<td>A string that is a list of one or more line delimiters that determine the substrings that become <var class="term">%sl</var> <var>Stringlist</var> 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 <var class="term">string</var> into substrings.
<p>
If this optional argument is not specified, the delimiter list that applies is <code>X'0D'</code>, <code>X'25'</code>, and <code>X'0D25'</code> (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.</p></td></tr>
 
<tr><th><var>StripTrailingNull</var></th>
<tr><th><var>StripTrailingNull</var></th>
<td><var>Boolean</var> value</td></tr>
<td>This [[Notation conventions for methods#Named parameters|name required]] argument is a <var>[[Boolean enumeration|boolean]]</var> value that indicates whether a trailing null line should be stripped.  <var>StripTrailingNull</var> is an optional argument that defaults to <var>true</var>, which results in a trailing null line being stripped.</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<li>The <var>[[CreateLines (Stringlist function)|CreateLines]]</var> function performs the inverse operation; that is, it creates a string by concatenating the items in a <var>Stringlist</var> with separator strings between the items.
</ul>
==Examples==
==Examples==
If <var>Longstring</var> <code>%ls</code> is <code>'every,good,boy,does,fine'</code>,                             
and <code>%sl</code> is a <var>Stringlist</var>, and you specify:
<p class="code">%sl = %ls:parselines(' ,')
%sl:print </p>
The result is:
<p class="code">every
good
boy 
does
fine </p>
==See also==
==See also==
<ul>
<li>The <var>Stringlist</var> class <var>[[ParseLines (Stringlist subroutine)|ParseLines]]</var> subroutine
</ul>
{{Template:String:ParseLines footer}}
{{Template:String:ParseLines footer}}

Latest revision as of 19:09, 23 July 2015

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