Substring/Top and tail: Difference between revisions

(add →‎Joy)
Line 1,076:
 
=={{header|JavaScript}}==
 
<syntaxhighlight lang="javascript">alert("knight".slice(1)); // strip first character
alert("socks".slice(0, -1)); // strip last character
alert("brooms".slice(1, -1)); // strip both first and last characters</syntaxhighlight>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">DEFINE
dropfirst == 1 drop;
droplast == dup size pred take.
 
"abcd" dropfirst.
"abcd" droplast.
"abcd" dropfirst droplast.</syntaxhighlight>
If a string is known to be non-empty, the <code>rest</code> operator could be used instead of <code>dropfirst</code>.
{{out}}
<pre>"bcd"
"abc"
"bc"</pre>
 
=={{header|jq}}==
559

edits