Center and Centre (String functions): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
{{Template:String:Center subtitle}}
For a given input string and suitable specified length, this function                               
For a given input string and suitable specified length, this function                               
returns a string of the requested length that has the original string                               
returns a string of the requested length that has the original string                               
Line 10: Line 12:
                                                                                                      
                                                                                                      
This [[Intrinsic classes|intrinsic]] function is available as of version 7.3 of the [[Sirius Mods]].
This [[Intrinsic classes|intrinsic]] function is available as of version 7.3 of the [[Sirius Mods]].
===Center syntax===  
==Syntax==
  %outStr = string:Center(length, [Pad=char] [, OffsetLeft=bool])
{{Template:String:Center syntax}}
===Syntax Terms===                                                                                
===Syntax terms===
<dl>   
<dl>   
<dt>%outStr                                                                       
<dt>%outStr                                                                       
Line 42: Line 44:
                                                                                  
                                                                                  
</dl>                                                                             
</dl>                                                                             
===Usage Notes===                                                              
==Usage notes==
*The ''length'' value must be a non-negative number; a negative number results in request cancellation.     
*The ''length'' value must be a non-negative number; a negative number results in request cancellation.     
For a ''length'' greater than 255, the output variable must be defined as a longstring.                 
For a ''length'' greater than 255, the output variable must be defined as a longstring.                 
A ''length'' value greater than the declared length of the output string results in a request cancellation.               
A ''length'' value greater than the declared length of the output string results in a request cancellation.               
*The pad parameter value must be either null or a single character. A longer value results in a compilation error.                       
*The pad parameter value must be either null or a single character. A longer value results in a compilation error.                       
===Examples===                                                     
==Examples==
                                                                      
                                                                      
The following request prints ''''++++Hello, World!+++'''',           
The following request prints ''''++++Hello, World!+++'''',           

Revision as of 05:14, 19 January 2011

Template:String:Center subtitle

For a given input string and suitable specified length, this function returns a string of the requested length that has the original string embedded in the center. If the requested length is larger than the length of the input string, pad characters are added to the input string to produce the returned string. If the requested length is shorter, the input string's front and end are cropped to produce the returned string.

'Centre' is a synonym for the Center function.

This intrinsic function is available as of version 7.3 of the Sirius Mods.

Syntax

%outString = string:Center( length, [Pad= c], [OffsetLeft= boolean])

Syntax terms

%outStr
A string variable to receive the result of the Center method.
string
The string to which the method is applied.
length
The number of characters in the output string. If this value is greater than the length of the method object string, the method object string is padded on the right and left to the requested length. If the method object is shorter than length, it is cropped on the left and right.
Pad=char
An optional, name-required, argument that indicates the character used to pad string on the right and left (if the length value is greater than the length of string). If an uneven number of pad characters is required, the location of the extra pad character is determined by the value of the Offsetleft parameter. The default for char is the blank character. Specifying an explicit null results in no padding.
OffsetLeft=bool
An optional, name-required, argument that is a boolean value indicating where to put the extra character if the requested padding or cropping is asymmetric. If the required number of pad characters or characters to be cropped is not even, the default ('False') is to produce an extra character on the right.

Usage notes

  • The length value must be a non-negative number; a negative number results in request cancellation.

For a length greater than 255, the output variable must be defined as a longstring. A length value greater than the declared length of the output string results in a request cancellation.

  • The pad parameter value must be either null or a single character. A longer value results in a compilation error.

Examples

The following request prints '++++Hello, World!+++', then 'llo, World'

   begin                                                            
     %x is string len 15                                            
     %out is  string len 20                                         
     %len is float                                                  
     %x = 'Hello, World!'                              
     %len = 20                                         
     %out = %x:center(%len, Pad='+', OffsetLeft=True)  
     printText {%out}          
                                                       
     %len = 10                                         
     %out = %x:center(%len, Pad='+', OffsetLeft=True)  
     printText {%out}                                  
   end

See also

List of intrinsic String methods