Substring/Top and tail: Difference between revisions
Content added Content deleted
(add →Joy) |
|||
Line 1,076: | Line 1,076: | ||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
<syntaxhighlight lang="javascript">alert("knight".slice(1)); // strip first character |
<syntaxhighlight lang="javascript">alert("knight".slice(1)); // strip first character |
||
alert("socks".slice(0, -1)); // strip last character |
alert("socks".slice(0, -1)); // strip last character |
||
alert("brooms".slice(1, -1)); // strip both first and last characters</syntaxhighlight> |
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}}== |
=={{header|jq}}== |