Documentation
Back to website >

SetStr (Pascalscript)

Description

The SetStr function can fill and align a string with a filler.

Syntax

function SetStr(Code, Filler: char; S: string; count: Integer): string;

Arguments

The text S is positioned in a count long text consisting of the fill character Filler depending on the value Code.

In this way, a simple formatting can be performed if Filler is passed as a space.

The possible values of code influence the positioning of the text S within the new output string. The output string is always count characters long. If count is smaller than the length of S, S is truncated either left or right accordingly. Which side S is truncated from depends on the code.

The following values apply to the code:

Code Behaviour
L The string S is left-aligned by a count long output string, which can be filled with the character Filler. If count is smaller than the length S, the string S is shortened on the right.
R The string S is placed right-aligned in an output string that is one count long and, if necessary, filled with the character Filler. If count is smaller than the length S, the string S is shortened on the left.
Z The string S is centered by a count long output string, which may be filled with the character Filler. If count is smaller than the length S, the string S is shortened equally on the right and left accordingly.

Excample

var
  S1: String;
  S2: String;
begin
  S1:='Hallo';
  S2:=SetStr('R','*',S1,10);
  ShowMessage(s2);
end;

Rules to understand the script can be found here.

The text 'Hello' is assigned to the string variable S1. The SetStr function positions the text right-aligned into a 10 character field of asterisks. The result is assigned to S2.

ShowMessage shows: *******Hello