CJustify()

Returns the given string justified to the center, padding out the words with spaces accordingly

CJustify( string=string, length=number );

Returns: String

Argument Description
string
string, required

May be empty. If it is a variable that is defined as a number, the function processes it as a string.

length
number, required

A positive integer. Length of field.

Examples

string = "A light-weight dynamic scripting language for the JVM.";
	dump(cJustify(string, 5));
<span class="c">// member function</span>
<span class="nf">dump</span><span class="p">(</span><span class="nf">string.cJustify</span><span class="p">(</span><span class="m">5</span><span class="p">));</span>
<span class="nv">s</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="p">;</span>
<span class="nv">res</span> <span class="o">=</span> <span class="nf">cJustify</span><span class="p">(</span><span class="nv">s</span><span class="p">,</span> <span class="m">4</span><span class="p">);</span>
<span class="nf">writeDump</span><span class="p">(</span><span class="k">len</span><span class="p">(</span><span class="nv">res</span><span class="p">));</span> <span class="c">// length is 4</span>
<span class="nf">writeoutput</span><span class="p">(</span><span class="s2">&quot;&lt;pre&gt;|</span><span class="s-Interp">#res#</span><span class="s2">|&lt;/pre&gt;&lt;hr&gt;&quot;</span><span class="p">);</span>
<span class="nv">s</span> <span class="o">=</span> <span class="s2">&quot;abc&quot;</span><span class="p">;</span>
<span class="nv">res</span> <span class="o">=</span> <span class="nf">cJustify</span><span class="p">(</span><span class="nv">s</span><span class="p">,</span> <span class="m">10</span><span class="p">);</span>
<span class="nf">writeDump</span><span class="p">(</span><span class="k">len</span><span class="p">(</span><span class="nv">res</span><span class="p">));</span> <span class="c">// length is 10</span>
<span class="nf">writeoutput</span><span class="p">(</span><span class="s2">&quot;&lt;pre&gt;|</span><span class="s-Interp">#res#</span><span class="s2">|&lt;/pre&gt;&lt;hr&gt;&quot;</span><span class="p">);</span>
<span class="nv">s</span> <span class="o">=</span> <span class="s2">&quot;10&quot;</span><span class="p">;</span>
<span class="nv">res</span> <span class="o">=</span> <span class="nf">cJustify</span><span class="p">(</span><span class="nv">s</span><span class="p">,</span> <span class="m">8</span><span class="p">);</span>
<span class="nf">writeDump</span><span class="p">(</span><span class="k">len</span><span class="p">(</span><span class="nv">res</span><span class="p">));</span> <span class="c">// length is 8</span>
<span class="nf">writeoutput</span><span class="p">(</span><span class="s2">&quot;&lt;pre&gt;|</span><span class="s-Interp">#res#</span><span class="s2">|&lt;/pre&gt;&quot;</span><span class="p">);</span>

See also