I have a method that's a bit different.
- define the length of field1 as $lg1=12; (you might have several fields of different length)
- for each line concatenate the text for the field with StrRepeat(' ', $lg1)

now length is at least $lg1
- get SubStr of this with Substr($v1 . StrRepeat(' ', $lg1), 0, $lg1)

length is exact $lg1
- if original string is too long it will be truncated
Example:
Code: Select all
$x = '1234567890'; // only demo to show column number
$lg1 = 12; // length of field1 (the only variable field here)
$v1 = 'abc'; // list of values (of different length)
$v2 = 'something';
$v3 = 'too long string here';
Text "$x$x$x<crlf 2>"
. 'LinePrefix: ' . Substr($v1 . StrRepeat(' ', $lg1), 0, $lg1) . "Field2<crlf>"
. 'LinePrefix: ' . Substr($v2 . StrRepeat(' ', $lg1), 0, $lg1) . "Field2<crlf>"
. 'LinePrefix: ' . Substr($v3 . StrRepeat(' ', $lg1), 0, $lg1) . "Field2<crlf>" ;
Sure you may build line for line in a loop and concatenate the lines, or whatever...
You might even use a subroutine for building a line.

(But XY and user subroutines - dream

)