Unspace (String function): Difference between revisions
Jump to navigation
Jump to search
m (1 revision) |
m (1 revision) |
||
Line 1: | Line 1: | ||
{{Template:String:Unspace subtitle}} | {{Template:String:Unspace subtitle}} | ||
This [[Intrinsic classes|intrinsic]] function removes the whitespace characters from | This [[Intrinsic classes|intrinsic]] function removes the whitespace characters from | ||
the method object string and it returns the resulting string. Options are available to: | 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 | *Define which character or characters are to be interpreted as whitespace | ||
*Remove leading whitespace, trailing whitespace, both or neither | *Remove leading whitespace, trailing whitespace, both or neither | ||
*Collapse to a single whitespace character any sequences of non-leading, non-trailing whitespace | *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]]. | The Unspace function is available as of version 7.3 of the [[Sirius Mods]]. | ||
==Syntax== | ==Syntax== | ||
{{Template:String:Unspace syntax}} | {{Template:String:Unspace syntax}} | ||
Line 25: | Line 25: | ||
<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>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> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
*Duplicate Spaces characters are tolerated and do not affect the result. | *Duplicate Spaces characters are tolerated and do not affect the result. | ||
Line 32: | Line 32: | ||
==Examples== | ==Examples== | ||
The following are example Unspace statements: | The following are example Unspace statements: | ||
%ls is longstring | %ls is longstring | ||
%ls = ' so me chars ' | %ls = ' so me chars ' | ||
[[Intrinsic classes#printtext|printText]] {~} = {%ls:unspace()} | [[Intrinsic classes#printtext|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)} | ||
The results are respectively: | The results are respectively: | ||
%ls:unspace() = so me chars | %ls:unspace() = so me chars | ||
%ls:unspace(Spaces='X ') = soXmeXchars | %ls:unspace(Spaces='X ') = soXmeXchars | ||
%ls:unspace(leading=false) = so me chars | %ls:unspace(leading=false) = so me chars | ||
%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 | ||
Revision as of 14:04, 19 January 2011
Remove whitespace characters from the string (String class)
This 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
The Unspace function is available as of version 7.3 of the Sirius Mods.
Syntax
%outString = string:Unspace[( [Spaces= string], [Leading= boolean], - [Trailing= boolean], [Compress= boolean])]
Syntax terms
%outStr | A variable to receive the string result of the Unspace method. |
---|---|
string | The input string or Longstring. |
Spaces=chars | 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. |
Leading=bool | 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. |
Trailing=bool | 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. |
Compress=bool | 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. |
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. The version 7.8 result of PrintText {~} = X{' ':unspace}X is:
' ':unspace = XX
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(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