Unspace (String function): Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 4: | Line 4: | ||
<ul> | <ul> | ||
<li>Define which character or characters are to be interpreted as whitespace | <li>Define which character or characters are to be interpreted as whitespace | ||
<li>Remove leading whitespace, trailing whitespace, both or neither | <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> | <li>Collapse to a single whitespace character any sequences of non-leading, non-trailing whitespace</ul> | ||
Line 48: | Line 48: | ||
%ls = ' so me chars ' | %ls = ' so me chars ' | ||
[[PrintText statement|printText]] {~} = {%ls:unspace()} | [[PrintText statement|printText]] {~} = '{%ls:unspace()}' | ||
printText {~} = {%ls:unspace(Spaces='X ')} | printText {~} = '{%ls:unspace(Spaces='X ')}' | ||
printText {~} = {%ls:unspace(leading=false)} | printText {~} = '{%ls:unspace(Spaces='X')}' | ||
printText {~} = {%ls:unspace(trailing=false)} | printText {~} = '{%ls:unspace(leading=false)}' | ||
printText {~} = {%ls:unspace(compress=false)} | printText {~} = '{%ls:unspace(trailing=false)}' | ||
printText {~} = '{%ls:unspace(compress=false)}' | |||
</p> | </p> | ||
The results are respectively: | The results are respectively: | ||
<p class="code">%ls:unspace() = so me chars | <p class="code">%ls:unspace() = 'so me chars' | ||
%ls:unspace(Spaces='X ') = soXmeXchars | %ls:unspace(Spaces='X ') = 'soXmeXchars' | ||
%ls:unspace(leading=false) = | %ls:unspace(Spaces='X') = ' so me chars' | ||
%ls:unspace(trailing=false) = so me chars | %ls:unspace(leading=false) = ' so me chars' | ||
%ls:unspace(compress=false) = so me chars | %ls:unspace(trailing=false) = 'so me chars ' | ||
%ls:unspace(compress=false) = 'so me chars' | |||
</p> | </p> | ||
==See also== | ==See also== | ||
{{Template:String:Unspace footer}} | {{Template:String:Unspace footer}} |
Revision as of 16:53, 31 July 2012
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 (which may be one) of 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 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
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'