tag:support.nodebox.net,2012-11-01:/discussions/show-your-work/134-maximum-length-string-trimmer-plus-bug-reportNodeBox: Discussion 2016-03-08T05:21:24Ztag:support.nodebox.net,2012-11-01:Comment/393398192016-03-07T19:39:54Z2016-03-07T19:39:54ZMaximum Length String Trimmer (Plus Bug Report)<div><p>OK that substring behavior is absolutely horrible!</p>
<p>I've checked and the code was actually provided by an outside
contributor (who shall remain unnamed :-). I think it is better if
we simplify this code so it doesn't try to do any "magic".</p>
<p>What I <em>really</em> don't like is that indexing starts at 1.
However, I'm afraid it's too late to change that...</p></div>Frederik De Blesertag:support.nodebox.net,2012-11-01:Comment/393398192016-03-07T21:05:37Z2016-03-07T21:06:20ZMaximum Length String Trimmer (Plus Bug Report)<div><p>John do you actually use the subString node often? And do you
use the end offset parameter? I didn't find any projects that use
this, so I wouldn't mind changing the behavior.</p>
<p>My idea to clean up this mess:</p>
<ul>
<li>Make indexing start at 0 (same for <code>characterAt</code>
node if possible)</li>
<li>Get rid of wrapping</li>
<li>If the end offset is too big, just clamp</li>
<li>If start and end offset are negative, indexing starts at the
end (like Python) (this should work in <code>characterAt</code> as
well)</li>
</ul></div>Frederik De Blesertag:support.nodebox.net,2012-11-01:Comment/393398192016-03-08T05:21:22Z2016-03-08T05:21:22ZMaximum Length String Trimmer (Plus Bug Report)<div><p>Frederik,</p>
<p>I don't use it very often. I occasionally use it to truncate
long strings, or to reverse names (from last, first to first last).
I found 12 occurrences in one large network, but that was the
exception, not the rule.</p>
<p>So personally I would be willing to adjust my past code for the
sake of 0-index purity.</p>
<p>As for the end offset parameter, I say toss it. I can see the
temptation, but it seems inelegant to add an extra parameter just
to add 1 to the endpoint. I prefer simple, consistent nodes to
nodes that sometimes do one thing, sometime another based on an
almost hidden setting - even if that means I have to insert an
extra "add 1" or "subtract 1" node now and then.</p>
<p>I like your plan (though would appreciate documentation
especially for the negative offsets).</p>
<p>Full speed ahead!</p>
<p>John</p></div>john