Substring/Top and tail: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Added AppleScript example.)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 144:
knight
night</pre>
 
=={{header|ALGOL 68}}==
{{trans|AWK}}
{{works with|ALGOL 68|Revision 1 - no extensions to language used.}}
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
<lang algol68>#!/usr/local/bin/a68g --script #
 
STRING str="upraisers";
printf(($gl$,
str, # remove no characters #
str[LWB str+1: ], # remove the first character #
str[ :UPB str-1], # remove the last character #
str[LWB str+1:UPB str-1], # remove both the first and last character #
str[LWB str+2: ], # remove the first 2 characters #
str[ :UPB str-2], # remove the last 2 characters #
str[LWB str+1:UPB str-2], # remove 1 before and 2 after #
str[LWB str+2:UPB str-1], # remove 2 before and one after #
str[LWB str+2:UPB str-2] # remove both the first and last 2 characters #
))</lang>
Output:
<pre>
upraisers
praisers
upraiser
praiser
raisers
upraise
praise
raiser
raise
</pre>
 
=={{header|Apex}}==
Line 210 ⟶ 242:
This is some tex
his is some tex"</pre>
 
=={{header|ALGOL 68}}==
{{trans|AWK}}
{{works with|ALGOL 68|Revision 1 - no extensions to language used.}}
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
<lang algol68>#!/usr/local/bin/a68g --script #
 
STRING str="upraisers";
printf(($gl$,
str, # remove no characters #
str[LWB str+1: ], # remove the first character #
str[ :UPB str-1], # remove the last character #
str[LWB str+1:UPB str-1], # remove both the first and last character #
str[LWB str+2: ], # remove the first 2 characters #
str[ :UPB str-2], # remove the last 2 characters #
str[LWB str+1:UPB str-2], # remove 1 before and 2 after #
str[LWB str+2:UPB str-1], # remove 2 before and one after #
str[LWB str+2:UPB str-2] # remove both the first and last 2 characters #
))</lang>
Output:
<pre>
upraisers
praisers
upraiser
praiser
raisers
upraise
praise
raiser
raise
</pre>
 
=={{header|AutoHotkey}}==
Line 248:
MsgBox % SubStr(MyString, 1, StrLen(MyString)-1)
MsgBox % SubStr(MyString, 2, StrLen(MyString)-2)</lang>
 
=={{header|AWK}}==
<lang awk>BEGIN {
Line 286 ⟶ 287:
KNIGHT
NIGHT</pre>
 
=={{header|BBC BASIC}}==
<lang bbcbasic> s$ = "Rosetta Code"
PRINT MID$(s$, 2)
PRINT LEFT$(s$)
PRINT LEFT$(MID$(s$, 2))</lang>
 
=={{header|Bracmat}}==
Line 337 ⟶ 344:
String with last character removed: 8-bit strin
String with both the first and last characters removed: -bit strin</pre>
 
=={{header|BBC BASIC}}==
<lang bbcbasic> s$ = "Rosetta Code"
PRINT MID$(s$, 2)
PRINT LEFT$(s$)
PRINT LEFT$(MID$(s$, 2))</lang>
 
=={{header|Burlesque}}==
Line 391 ⟶ 392:
 
ANSI C provides little functionality for text manipulation outside of string.h. While a number of libraries for this purpose have been written, this example uses only ANSI C.
 
=={{header|C++}}==
<lang cpp>#include <string>
#include <iostream>
 
int main( ) {
std::string word( "Premier League" ) ;
std::cout << "Without first letter: " << word.substr( 1 ) << " !\n" ;
std::cout << "Without last letter: " << word.substr( 0 , word.length( ) - 1 ) << " !\n" ;
std::cout << "Without first and last letter: " << word.substr( 1 , word.length( ) - 2 ) << " !\n" ;
return 0 ;
}</lang>
Output:
<PRE>Without first letter: remier League !
Without last letter: Premier Leagu !
Without first and last letter: remier Leagu !
</PRE>
 
=={{header|C sharp}}==
Line 429 ⟶ 413:
tes
es</pre>
 
=={{header|C++}}==
<lang cpp>#include <string>
#include <iostream>
 
int main( ) {
std::string word( "Premier League" ) ;
std::cout << "Without first letter: " << word.substr( 1 ) << " !\n" ;
std::cout << "Without last letter: " << word.substr( 0 , word.length( ) - 1 ) << " !\n" ;
std::cout << "Without first and last letter: " << word.substr( 1 , word.length( ) - 2 ) << " !\n" ;
return 0 ;
}</lang>
Output:
<PRE>Without first letter: remier League !
Without last letter: Premier Leagu !
Without first and last letter: remier Leagu !
</PRE>
 
=={{header|Clojure}}==
Line 544 ⟶ 545:
2013-09-04 17:08:09.454 a.out[2257:507] room
2013-09-04 17:08:09.455 a.out[2257:507] ημοτικ</pre>
 
=={{header|Elena}}==
ELENA 4.x :
Line 617 ⟶ 619:
puts(1, strip_last("write")) -- strip last character
puts(1, strip_both("brooms")) -- strip both first and last characters</lang>
 
 
=={{header|F_Sharp|F#}}==
Line 727 ⟶ 728:
First and last removed: ημοτικ
</pre>
 
=={{header|GW-BASIC}}==
<lang qbasic>10 A$="knight":B$="socks":C$="brooms"
20 PRINT MID$(A$,2)
30 PRINT LEFT$(B$,LEN(B$)-1)
40 PRINT MID$(C$,2,LEN(C$)-2)</lang>
 
=={{header|Groovy}}==
Line 753 ⟶ 748:
tail: praisers
top&tail: praiser</pre>
 
=={{header|GW-BASIC}}==
<lang qbasic>10 A$="knight":B$="socks":C$="brooms"
20 PRINT MID$(A$,2)
30 PRINT LEFT$(B$,LEN(B$)-1)
40 PRINT MID$(C$,2,LEN(C$)-2)</lang>
 
=={{header|Haskell}}==
Line 949 ⟶ 950:
ÜÄÖ
 
Ä =={{header|Lasso}}==
Ä
<lang Lasso>local(str = 'The quick grey rhino jumped over the lazy green fox.')
 
// String with first character removed
string_remove(#str,-startposition=1,-endposition=1)
// > he quick grey rhino jumped over the lazy green fox.
 
// String with last character removed
string_remove(#str,-startposition=#str->size,-endposition=#str->size)
// > The quick grey rhino jumped over the lazy green fox
 
// String with both the first and last characters removed
string_remove(string_remove(#str,-startposition=#str->size,-endposition=#str->size),-startposition=1,-endposition=1)
// > he quick grey rhino jumped over the lazy green fox</lang>
 
=={{header|Liberty BASIC}}==
Line 969 ⟶ 983:
30 PRINT LEFT$(b$,LEN(b$)-1)
40 PRINT MID$(c$,2,LEN(c$)-2)</lang>
 
=={{header|Lasso}}==
<lang Lasso>local(str = 'The quick grey rhino jumped over the lazy green fox.')
 
// String with first character removed
string_remove(#str,-startposition=1,-endposition=1)
// > he quick grey rhino jumped over the lazy green fox.
 
// String with last character removed
string_remove(#str,-startposition=#str->size,-endposition=#str->size)
// > The quick grey rhino jumped over the lazy green fox
 
// String with both the first and last characters removed
string_remove(string_remove(#str,-startposition=#str->size,-endposition=#str->size),-startposition=1,-endposition=1)
// > he quick grey rhino jumped over the lazy green fox</lang>
 
=={{header|Logo}}==
Line 1,237 ⟶ 1,236:
print $bits; # h
print $string; # ouc # See we really did chop the last letter off</lang>
 
=={{header|Perl 6}}==
 
Perl 6 provides both functional and method forms of substr. Note that, unlike in Perl 5, offsets from the end do not use negative numbers, but instead require a function expressing the negative offset relative to the length parameter, which is supplied by the operator. The form <tt>*-1</tt> is just a simple way to write such a function.
 
We use musical sharps and flats to illustrate that Perl is comfortable with characters from any Unicode plane.
 
<lang perl6>my $s = '𝄪♯♮♭𝄫';
 
print qq:to/END/;
Original:
$s
 
Remove first character:
{ substr($s, 1) }
{ $s.substr(1) }
 
Remove last character:
{ substr($s, 0, *-1) }
{ $s.substr( 0, *-1) }
{ $s.chop }
 
Remove first and last characters:
{ substr($s, 1, *-1) }
{ $s.substr(1, *-1) }
END</lang>
{{out}}
<pre>Original:
𝄪♯♮♭𝄫
 
Remove first character:
♯♮♭𝄫
♯♮♭𝄫
Remove last character:
𝄪♯♮♭
𝄪♯♮♭
𝄪♯♮♭
Remove first and last characters:
♯♮♭
♯♮♭</pre>
 
=={{header|Phix}}==
Line 1,478 ⟶ 1,435:
"トリン"
</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
 
Perl 6 provides both functional and method forms of substr. Note that, unlike in Perl 5, offsets from the end do not use negative numbers, but instead require a function expressing the negative offset relative to the length parameter, which is supplied by the operator. The form <tt>*-1</tt> is just a simple way to write such a function.
 
We use musical sharps and flats to illustrate that Perl is comfortable with characters from any Unicode plane.
 
<lang perl6>my $s = '𝄪♯♮♭𝄫';
 
print qq:to/END/;
Original:
$s
 
Remove first character:
{ substr($s, 1) }
{ $s.substr(1) }
 
Remove last character:
{ substr($s, 0, *-1) }
{ $s.substr( 0, *-1) }
{ $s.chop }
 
Remove first and last characters:
{ substr($s, 1, *-1) }
{ $s.substr(1, *-1) }
END</lang>
{{out}}
<pre>Original:
𝄪♯♮♭𝄫
 
Remove first character:
♯♮♭𝄫
♯♮♭𝄫
Remove last character:
𝄪♯♮♭
𝄪♯♮♭
𝄪♯♮♭
Remove first and last characters:
♯♮♭
♯♮♭</pre>
 
=={{header|Raven}}==
10,327

edits