Right (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 40: Line 40:
[[Category:Intrinsic String methods|Right function]]
[[Category:Intrinsic String methods|Right function]]
[[Category:Intrinsic methods]]
[[Category:Intrinsic methods]]
[[Category:System methods]]

Revision as of 20:00, 31 December 2010

This intrinsic function returns the right-most characters of the method object string, possibly padding it on the left.

Right is available as of version 7.2 of the Sirius Mods.

Right syntax

  %outStr = string:right(length [, pad=char])                                                              

Syntax Terms

%outStr
A variable to receive the string result of the Right method.
string
The string to which the method is applied.
length
The number of the right-most bytes to return. If the method object is shorter than the requested bytes, it is either padded to the requested length or the entire method object string is returned with no padding, depending on the value of the Pad parameter.
Pad=char
The character used to pad the method object string on the left if it is shorter than the requested length. char defaults to a blank. If set to null, no padding is applied. Pad is a name-required parameter.

Usage Notes

  • The length must be a non-negative number. A negative number results in request cancellation.
  • The pad parameter must be either null or a single character. A longer value results in request cancellation in Sirius Mods version 7.2 and in a compilation error in Sirius Mods 7.3 and higher.
  • The Right method can be useful for right-justifying a value in a string, most typically by using a blank as pad character.

Examples

The following places the right-most 5 bytes of %x into %y. If %x is shorter than 6 bytes, then all of %x is copied into %y:

   %y = %x:right(5)                                                                                   

The following request right-justifies the numbers 7, 123, and 99, and it left-justifies the number 88:

   Begin                                                                                              
     printText {7:right(5)}                                                   
     printText {123:right(5)}                                                                         
     printText {99:right(5)}                                                                          
     printText {88:right(5, pad=)}                                                                  
   End

See also

List of intrinsic String methods