Substring/Top and tail: Difference between revisions
Content added Content deleted
(Added D version) |
|||
Line 39: | Line 39: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<lang awk>BEGIN { |
<lang awk>BEGIN { |
||
mystring="knights" |
mystring="knights" |
||
Line 45: | Line 44: | ||
print substr(mystring,1,length(mystring)-1) # remove the last character |
print substr(mystring,1,length(mystring)-1) # remove the last character |
||
print substr(mystring,2,length(mystring)-2) # remove both the first and last character |
print substr(mystring,2,length(mystring)-2) # remove both the first and last character |
||
}</lang> |
|||
=={{header|D}}== |
|||
Version for ASCII strings: |
|||
<lang d>import std.stdio; |
|||
void main() { |
|||
writeln("knight"[1..$]); // strip first character |
|||
writeln("socks"[0..$-1]); // strip last character |
|||
writeln("brooms"[1..$-1]); // strip both first and last characters |
|||
}</lang> |
}</lang> |
||