|
A function that can be used in Formulas.
padOrTruncateRight$ (string$, newWidth [, pad$])
pad$) to the right of string$, or remove characters from the right of string$, until the result is precisely newWidth characters long: assert padOrTruncateRight$ ("hello", 12, ".") = "hello......."
assert padOrTruncateRight$ ("hello", 3, ".") = "hel"
assert padOrTruncateRight$ ("hello", 0) = ""
If pad$ is not given, the padding will be done with spaces:
assert padOrTruncateRight$ ("hello", 12) = "hello "
assert padOrTruncateRight$ ("hello", 3) = "hel"
If characters have to be added, and pad$ contains more than one character, the right edge of pad$ is right-aligned to the resulting string, so that the result will look good if padding is used for visualizing columns:
assert padOrTruncateRight$ ("hello", 12, ".-;)") = "hello-;).-;)"
assert padOrTruncateRight$ ("goodbye", 12, ".-;)") = "goodbye).-;)"
Note that newWidth cannot be negative:
asserterror Can never truncate a string down to -3 characters.
a$ = padOrTruncateRight$ ("hello", -3)
There will be an error message if padding is required but no characters are to be found in pad$:
asserterror Empty pad string.
a$ = padOrTruncateRight$ ("hello", 12, "")
© Paul Boersma 2024