Compatible Unicode Intrinsic Functions - Center Method

Center the string within the variable

Member of Compatible Unicode Intrinsic Functions (PRIM_LIBI.ICompatibleUnicodeIntrinsics)

Parameters

Name Type Data Type Description
Result *Result (Optional) Unicode String Resulting centered string
Length *Input (Optional) Integer Length parameter
Pad *Input (Optional) Unicode String Padding character used when the string doesn't fill the variable

Details

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. This does not guarantee that the result will be visually centered if the font being used in non-proportional.

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)

See also

All Component Classes

Technical Reference

LANSA Version 15, April 2020