10 6 15 Center and Centre

LANSA Technical

10.6.15 Center and Centre

Center allows a string to be centered within a given length, and will optionally pad the result with a supplied character. Leading and trailing spaces are significant and will be evaluated as part of the string to center.

If the string is longer than the target variable, the first n bytes of the string are used. Where the result of centering the string results is an uneven number of bytes, the extra byte will be allocated to the right-hand side.

Typically, centering is used to center a value within a target variable. By using the Length parameter you can control how the string is centered and padded.

Center can only be used to center a string within a target string, which does not guarantee that the result will be visually centered in a Windows run-time environment.

Input Parameters

Length - Length of the string to be centered in

Pad - Character to pad either side of the centered string.

Example

In this example, if string is a 40 byte variable that contains a value of "Centered Text", the result is "***Centered Text****". The remaining 20 bytes of #string will be null:

#Target := #string.Center(20 '*')

 

In this example, where string is a 20 byte variable that contains a value of "Centered Text", the result would be "  Centered Text  ".  This is a typical centering scenario where the length of the target governs the centering of the text:

 

#Target := #string.Center( #Target.FieldLength)

 

Ý 10.6 Alphanumeric/String Intrinsic Functions