Jump to content

Substring/Top and tail: Difference between revisions

jq
m (→‎{{header|Ruby}}: added comment)
(jq)
Line 535:
alert("brooms".slice(1, -1)); // strip both first and last characters</lang>
 
=={{header|jq}}==
jq uses 0-based indexing, so [1:] yields all but the first character, it being understood that data strings in jq are JSON strings. [0:-1], which can be abbreviated to [:-1], yields all but the last character, and so on. Here are some examples:<lang jq>"一二三四五六七八九十"[1:]' => "二三四五六七八九十"
 
"一二三四五六七八九十"[:-1]' => "一二三四五六七八九"
 
"一二三四五六七八九十"[1:-1]' => "二三四五六七八九"
 
"a"[1:-1] # => ""
</lang>
=={{header|Julia}}==
<lang julia>julia> "My String"[2:end] # without first character
2,489

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.