Substring/Top and tail: Difference between revisions

Added Maple implementation
m (→‎{{header|REXX}}: added a comment. -- ~~~~)
(Added Maple implementation)
Line 454:
print (string.sub("knights",1,-2)) -- remove the last character
print (string.sub("knights",2,-2)) -- remove the first and last characters</lang>
 
=={{header|Maple}}==
There are several ways to do this. The first is, I think, the simplest.
<lang Maple>> s := "some string":
> s[2..-1];
"ome string"
 
> s[1..-2];
"some strin"
 
> s[2..-2];
"ome strin"</lang>
The same functionality exists in the form of a procedure:
<lang Maple>> substring( s, 2 .. -1 );
"ome string"
 
> substring( s, 1 .. -2 );
"some strin"
 
> substring( s, 2 .. -2 );
"ome strin"</lang>
Furthermore, there is a slightly different version in the "StringTools" package:
<lang Maple>> use StringTools in
> SubString( s, 2 .. -1 );
> SubString( s, 1 .. -1 );
> SubString( s, 2 .. -2 )
> end use;
"ome string"
 
"some string"
 
"ome strin"</lang>
(The difference between "substring" and "StringTools:-SubString" lies in how each treats a name as input; the former returns a name, while the latter returns a string.)
 
=={{header|Mathematica}}==
Anonymous user