Unspace (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
 
Line 31: Line 31:
===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.
*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.
*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 <tt>PrintText {~} = X{'    ':unspace}X</tt> is:
  '    ':unspace = XX


===Examples===                                                                                   
===Examples===                                                                                   

Revision as of 23:40, 14 December 2010

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.

Unspace syntax

  %outStr = string:Unspace( [Spaces=chars] [, Leading=bool] [, Trailing=bool] [, Compress=bool] ) 

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

See also

List of Intrinsic String Methods