Unspace (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (match syntax diagram to revised template and fix tags; still some incomplete / unfound links)
Line 1: Line 1:
{{Template:String:Unspace subtitle}}
{{Template:String:Unspace subtitle}}


This [[Intrinsic classes|intrinsic]] function removes the whitespace characters from
The <var>Unspace</var> [[Intrinsic classes|intrinsic]] function removes the whitespace characters from the method object string and it returns the resulting string. Options are available to:<ul><li>
the method object string and it returns the resulting string. Options are available to:
Define which character or characters are to be interpreted as whitespace<li>Remove leading whitespace, trailing whitespace, both or neither;<li>Collapse to a single whitespace character any sequences of non-leading, non-trailing whitespace</ul>
*Define which character or characters are to be interpreted as whitespace
*Remove leading whitespace, trailing whitespace, both or neither
*Collapse to a single whitespace character any sequences of non-leading, non-trailing whitespace


The <var>Unspace</var> function is available as of version 7.3 of the <var class=product>Sirius Mods</var>.
==Syntax==
==Syntax==
{{Template:String:Unspace syntax}}
{{Template:String:Unspace syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%outStr</th>
<tr><th>%outString</th>
<td>A variable to receive the string result of the <var>Unspace</var> method.                                 </td></tr>
<td>A variable to receive the string result of the <var>Unspace</var> method.</td></tr>
<tr><th>string</th>
<tr><th>string</th>
<td>The input string or <var>Longstring</var>.                                                                </td></tr>
<td>The input method object string</td></tr>
<tr><th>Spaces=chars</th>
<tr><th>Spaces</th>
<td>The optional Spaces argument (name required) is a string that specifies the set of characters considered to be whitespace. The default set is the blank character.                                                                                                   If you specify multiple Spaces characters:                                                         *There is no separator character.                                                                 *The first character of the string is the replacement space character: a single one of these is substituted for each sequence (which may be one) of non-leading, non-trailing Spaces characters in the method object string.                       </td></tr>
<td><var class="term">Spaces</var> is an optional, but <var class="term">nameRequired</var>, parameter, which is a string that specifies the set of characters considered to be whitespace. The default set is the blank space (<code>' '</code>) character. If you specify multiple <var class="term">Spaces</var> characters:<ul><li>There is no separator character.<li>The first character of the string is the replacement space character: a single one of these is substituted for each sequence (which may be one) of non-leading, non-trailing Spaces characters in the method object string.</ul></td></tr>
<tr><th>Leading=bool</th>
<tr><th>Leading</th>
<td>The optional Leading argument (name required) is a Boolean value that specifies whether to strip all leading whitespace characters. The default is ''''True'''', strip leading whitespace.                                             </td></tr>
<td><var class="term">Leading</var> is an optional, but <var class="term">nameRequired</var>, parameter, which is a <var>[[Boolean Enumeration]]</var> value that specifies whether to strip all leading whitespace characters. The default is <var>True</var>, strip leading whitespace.</td></tr>
<tr><th>Trailing=bool</th>
<tr><th>Trailing</th>
<td>The optional Trailing argument (name required) is a Boolean value that specifies whether to strip all trailing whitespace characters. The default is ''''True'''', strip trailing whitespace.       </td></tr>
<td><var class="term">Trailing</var> is an optional, but <var class="term">nameRequired</var>, parameter, which is a <var>[[Boolean Enumeration]]</var> value that specifies whether to strip all trailing whitespace characters. The default is <var>True</var>, strip trailing whitespace.</td></tr>
<tr><th>Compress=bool</th>
<tr><th>Compress</th>
<td>The optional Compress argument (name required) is a Boolean value that specifies whether to collapse non-leading, non-trailing sequences of spaces to single spaces. The default is ''''True'''', collapse such sequences.</td></tr>
<td><var class="term">Compress</var> is an optional, but <var class="term">nameRequired</var>, parameter, which is a <var>[[Boolean Enumeration]]</var> value that specifies whether to collapse non-leading, non-trailing sequences of spaces to single spaces. The default is <var>True</var>, collapse such sequences.</td></tr>
</table>
</table>


==Usage notes==
==Usage notes==
*Duplicate Spaces characters are tolerated and do not affect the result.
<ul><li>Duplicate Spaces characters are tolerated and do not affect the result.
*Prior to Version 7.8 of the <var class=product>Sirius Mods</var>, <var>Unspace</var> compressed a string consisting entirely of whitespace characters to a single whitespace character. As of version 7.8 (and also in version 7.7 maintenance), <var>Unspace</var> converts a string of whitespace characters to a null string. The version 7.8 result of <tt>PrintText {~} = X{'    ':unspace}X</tt> is:
<li>Prior to <var class="product">Sirius Mods</var> Version 7.8, <var>Unspace</var> compressed a string consisting entirely of whitespace characters to a single whitespace character. As of Version 7.8 (and also in Version 7.7 maintenance), <var>Unspace</var> converts a string of whitespace characters to a null string. The Version 7.8 result of <code>printText {~} = X{'    ':unspace}X</code> is:
<p class="output">'    ':unspace = XX
<p class="output">'    ':unspace = XX
</p>
<li><var>Unspace</var> is available as of <var class="product">[[Sirius Mods]]</var> version 7.3.</ul>


</p>
==Examples==
==Examples==
 
<ol><li>The following are example <var>Unspace</var> statements:
The following are example <var>Unspace</var> statements:
<p class="code">%ls is longstring
<p class="code">%ls is longstring
%ls = '    so  me    chars  '
%ls = '    so  me    chars  '


[[Intrinsic classes#printtext|printText]] {~} = {%ls:unspace()}
printText {~} = {%ls:unspace()}
PrintText {~} = {%ls:unspace(Spaces='X ')}
printText {~} = {%ls:unspace(Spaces='X ')}
PrintText {~} = {%ls:unspace(leading=false)}
printText {~} = {%ls:unspace(leading=false)}
PrintText {~} = {%ls:unspace(trailing=false)}
printText {~} = {%ls:unspace(trailing=false)}
PrintText {~} = {%ls:unspace(compress=false)}
printText {~} = {%ls:unspace(compress=false)}
 
</p>
</p>
The results are respectively:
The results are respectively:
Line 51: Line 46:
%ls:unspace(trailing=false) = so me chars
%ls:unspace(trailing=false) = so me chars
%ls:unspace(compress=false) = so  me    chars
%ls:unspace(compress=false) = so  me    chars
</p></ol>


</p>
==See also==
==See also==
<ul><li>For details of the <var>printtext</var> statement, please see <var>[[Intrinsic classes#printtext|printText]]
{{Template:String:Unspace footer}}
{{Template:String:Unspace footer}}

Revision as of 22:29, 2 February 2011

Remove whitespace characters from the string (String class)


The Unspace intrinsic function removes the whitespace characters from the method object string and it returns the resulting string. Options are available to:

  • Define which character or characters are to be interpreted as whitespace
  • Remove leading whitespace, trailing whitespace, both or neither;
  • Collapse to a single whitespace character any sequences of non-leading, non-trailing whitespace

Syntax

%outString = string:Unspace[( [Spaces= string], [Leading= boolean], - [Trailing= boolean], [Compress= boolean])]

Syntax terms

%outString A variable to receive the string result of the Unspace method.
string The input method object string
Spaces Spaces is an optional, but nameRequired, parameter, which is a string that specifies the set of characters considered to be whitespace. The default set is the blank space (' ') character. If you specify multiple Spaces characters:
  • There is no separator character.
  • The first character of the string is the replacement space character: a single one of these is substituted for each sequence (which may be one) of non-leading, non-trailing Spaces characters in the method object string.
Leading Leading is an optional, but nameRequired, parameter, which is a Boolean Enumeration value that specifies whether to strip all leading whitespace characters. The default is True, strip leading whitespace.
Trailing Trailing is an optional, but nameRequired, parameter, which is a Boolean Enumeration value that specifies whether to strip all trailing whitespace characters. The default is True, strip trailing whitespace.
Compress Compress is an optional, but nameRequired, parameter, which is a Boolean Enumeration value that specifies whether to collapse non-leading, non-trailing sequences of spaces to single spaces. The default is True, collapse such sequences.

Usage notes

  • Duplicate Spaces characters are tolerated and do not affect the result.
  • Prior to Sirius Mods Version 7.8, Unspace compressed a string consisting entirely of whitespace characters to a single whitespace character. As of Version 7.8 (and also in Version 7.7 maintenance), Unspace converts a string of whitespace characters to a null string. The Version 7.8 result of printText {~} = X{' ':unspace}X is:

    ' ':unspace = XX

  • Unspace is available as of Sirius Mods version 7.3.

Examples

  1. The following are example Unspace statements:

    %ls is longstring %ls = ' so me chars ' printText {~} = {%ls:unspace()} printText {~} = {%ls:unspace(Spaces='X ')} printText {~} = {%ls:unspace(leading=false)} printText {~} = {%ls:unspace(trailing=false)} printText {~} = {%ls:unspace(compress=false)}

    The results are respectively:

    %ls:unspace() = so me chars %ls:unspace(Spaces='X ') = soXmeXchars %ls:unspace(leading=false) = so me chars %ls:unspace(trailing=false) = so me chars %ls:unspace(compress=false) = so me chars

See also