Unspace (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
 
m (Spell 'onr' more better.)
 
(49 intermediate revisions by 7 users not shown)
Line 1: Line 1:
This [[Intrinsic Classes|intrinsic]] function removes the whitespace characters from             
{{Template:String:Unspace subtitle}}
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                           
                                                                                                 
The Unspace function is available as of version 7.3 of the [[Sirius Mods]].                       
===Unspace syntax===                                                                             
  %outStr = string:Unspace( [Spaces=chars] [, Leading=bool] [, Trailing=bool] [, Compress=bool] )
===Syntax Terms===                                                                               
<dl>                                                                                             
<dt><i>%outStr</i> 
<dd>A variable to receive the string result of the Unspace method.                               
<dt><i>string</i> 
<dd>The input string or Longstring.                                                               
<dt>Spaces=<i>chars</i>
<dd>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.                       
<dt>Leading=<i>bool</i>
<dd>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.                                           
<dt>Trailing=<i>bool</i>
<dd>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.     
<dt>Compress=<i>bool</i>
<dd>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.                                           
                                                                                               
</dl>                                                                                           
===Usage Notes===                                                                               
*Duplicate Spaces characters are tolerated and do not affect the result.
*Prior to Version 7.8 of the ''Sirius Mods'', 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.


===Examples===                                                                                 
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>
The following are example Unspace statements:                                                   
<li>Define which character or characters are to be interpreted as whitespace
    %ls is longstring                                                                           
<li>Remove leading whitespace, trailing whitespace, both, or neither
    %ls = '    so  me    chars  '                                                             
<li>Collapse to a single whitespace character any sequences of non-leading, non-trailing whitespace</ul>
                                                                                               
    [[PrintText statement|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===
==Syntax==
[[List of Intrinsic String Methods]]
{{Template:String:Unspace syntax}}


[[Category:Intrinsic String methods|Unspace function]]
===Syntax terms===
[[Category:Intrinsic methods]]
<table class="syntaxTable">
[[Category:System methods]]
<tr><th>%outString</th>
<td>A variable to receive the string result of the <var>Unspace</var> method.</td></tr>
 
<tr><th>string</th>
<td>The input method object string</td></tr>
 
<tr><th><var>Spaces</var></th>
<td><var>Spaces</var> is an optional, [[Notation conventions for methods#Named parameters|name required]], parameter that is a string that specifies the set of characters considered to be whitespace. The default set is the blank space (<code>' '</code>) character. 
<p>If you specify multiple <var>Spaces</var> characters, the first character of the string is the replacement space character: a single one of these is substituted for each sequence of one or more non-leading, non-trailing <var>Spaces</var> characters in the method object string.</p></td></tr>
 
<tr><th><var>Leading</var></th>
<td><var>Leading</var> is an optional, name required, parameter that is a <var>[[Enumerations#Using_Boolean_enumerations|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><var>Trailing</var></th>
<td><var>Trailing</var> is an optional, name required, parameter that is a <var>Boolean</var> enumeration value that specifies whether to strip all trailing whitespace characters. The default is <var>True</var>, strip trailing whitespace.</td></tr>
 
<tr><th><var>Compress</var></th>
<td><var>Compress</var> is an optional, name required, parameter that is a <var>Boolean</var> enumeration value that specifies whether to collapse each sequence of spaces to a single space. The default is <var>True</var>, collapse such sequences.</td></tr>
</table>
 
==Usage notes==
<ul>
<li>Duplicate <var>Spaces</var> characters are tolerated and do not affect the result.
<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
<p class="code">printText {~} = X{'    ':unspace}X</p>
is:
<p class="output">'    ':unspace = XX
</p>
<li><var>Unspace</var> is available as of <var class="product">Sirius Mods</var> Version 7.3.
</ul>
 
==Examples==
The following are example <var>Unspace</var> statements:
<p class="code">%ls is longstring
%ls = '    so  me    chars  '
 
[[PrintText statement|printText]] {~} = '{%ls:unspace()}'
printText {~} = '{%ls:unspace(Spaces='X ')}'
printText {~} = '{%ls:unspace(Spaces='X')}'
printText {~} = '{%ls:unspace(leading=false)}'
printText {~} = '{%ls:unspace(trailing=false)}'
printText {~} = '{%ls:unspace(compress=false)}'
</p>
The results are respectively:
<p class="code">%ls:unspace() = 'so me chars'
%ls:unspace(Spaces='X ') = 'soXmeXchars'
%ls:unspace(Spaces='X') = '    so  me    chars' 
%ls:unspace(leading=false) = ' so me chars'
%ls:unspace(trailing=false) = 'so me chars '
%ls:unspace(compress=false) = 'so  me    chars'
</p>
 
==See also==
{{Template:String:Unspace footer}}

Latest revision as of 21:39, 11 August 2015

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, name required, parameter that 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, the first character of the string is the replacement space character: a single one of these is substituted for each sequence of one or more non-leading, non-trailing Spaces characters in the method object string.

Leading Leading is an optional, name required, parameter that 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, name required, parameter that 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, name required, parameter that is a Boolean enumeration value that specifies whether to collapse each sequence of spaces to a single space. 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

The following are example Unspace statements:

%ls is longstring %ls = ' so me chars ' printText {~} = '{%ls:unspace()}' printText {~} = '{%ls:unspace(Spaces='X ')}' 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(Spaces='X') = ' so me chars' %ls:unspace(leading=false) = ' so me chars' %ls:unspace(trailing=false) = 'so me chars ' %ls:unspace(compress=false) = 'so me chars'

See also