| 1 |
<html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 |
<title>padOrTruncateRight$</title> |
| 3 |
<style> |
| 4 |
td { padding-left: 5pt; padding-right: 5pt; } |
| 5 |
th { padding-left: 5pt; padding-right: 5pt; } |
| 6 |
code { white-space: pre-wrap; } |
| 7 |
dd { white-space: pre-wrap; } |
| 8 |
</style> |
| 9 |
</head><body bgcolor="#FFFFFF"> |
| 10 |
|
| 11 |
<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Monaco,Courier" size=6 color="#999900"><b> |
| 12 |
padOrTruncateRight$ |
| 13 |
</b></font></table></table> |
| 14 |
<p>A function that can be used in <a href="Formulas.html">Formulas</a>.</p> |
| 15 |
<h2>Syntax and semantics</h2> |
| 16 |
<dl> |
| 17 |
<dt><b><code><font size=+1>padOrTruncateRight$</font></code></b> (<i><code><font size=+1>string$</font></code></i>, <i><code><font size=+1>newWidth</font></code></i> [, <i><code><font size=+1>pad$</font></code></i>]) |
| 18 |
<dd>add characters (selected from <i><code><font size=+1>pad$</font></code></i>) to the right of <i><code><font size=+1>string$</font></code></i>, or remove characters from the right of <i><code><font size=+1>string$</font></code></i>, until the result is precisely <i><code><font size=+1>newWidth</font></code></i> characters long:</dd> |
| 19 |
</dl> |
| 20 |
<code> <a href="_assert_.html">assert</a> <b>padOrTruncateRight$</b> ("hello", 12, ".") = "hello......."<br></code> |
| 21 |
<code> <a href="_assert_.html">assert</a> <b>padOrTruncateRight$</b> ("hello", 3, ".") = "hel"<br></code> |
| 22 |
<code> <a href="_assert_.html">assert</a> <b>padOrTruncateRight$</b> ("hello", 0) = ""<br></code> |
| 23 |
<p>If <i><code><font size=+1>pad$</font></code></i> is not given, the padding will be done with spaces:</p> |
| 24 |
<code> <a href="_assert_.html">assert</a> <b>padOrTruncateRight$</b> ("hello", 12) = "hello "<br></code> |
| 25 |
<code> <a href="_assert_.html">assert</a> <b>padOrTruncateRight$</b> ("hello", 3) = "hel"<br></code> |
| 26 |
<p>If characters have to be added, and <i><code><font size=+1>pad$</font></code></i> contains more than one character, the right edge of <i><code><font size=+1>pad$</font></code></i> is right-aligned to the resulting string, so that the result will look good if padding is used for visualizing columns:</p> |
| 27 |
<code> <a href="_assert_.html">assert</a> <b>padOrTruncateRight$</b> ("hello", 12, ".-;)") = "hello-;).-;)"<br></code> |
| 28 |
<code> <a href="_assert_.html">assert</a> <b>padOrTruncateRight$</b> ("goodbye", 12, ".-;)") = "goodbye).-;)"<br></code> |
| 29 |
<p>Note that <i><code><font size=+1>newWidth</font></code></i> cannot be negative:</p> |
| 30 |
<code> <a href="_asserterror_.html">asserterror</a> Can never truncate a string down to -3 characters.<br></code> |
| 31 |
<code> a$ = <b>padOrTruncateRight$</b> ("hello", -3)<br></code> |
| 32 |
<p>There will be an error message if padding is required but no characters are to be found in <i><code><font size=+1>pad$</font></code></i>:</p> |
| 33 |
<code> <a href="_asserterror_.html">asserterror</a> Empty pad string.<br></code> |
| 34 |
<code> a$ = <b>padOrTruncateRight$</b> ("hello", 12, "")<br></code> |
| 35 |
<h3>Links to this page</h3> |
| 36 |
<ul> |
| 37 |
<li><a href="Functions.html">Functions</a> |
| 38 |
</ul> |
| 39 |
<hr> |
| 40 |
<address> |
| 41 |
<p>© Paul Boersma 2024</p> |
| 42 |
</address> |
| 43 |
</body> |
| 44 |
</html> |