This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -0,0 +1,12 @@
:- object(top_and_tail).
:- public(test/1).
test(String) :-
sub_atom(String, 1, _, 0, MinusTop),
write('String with first character cut: '), write(MinusTop), nl,
sub_atom(String, 0, _, 1, MinusTail),
write('String with last character cut: '), write(MinusTail), nl,
sub_atom(String, 1, _, 1, MinusTopAndTail),
write('String with first and last characters cut: '), write(MinusTopAndTail), nl.
:- end_object.

View file

@ -0,0 +1,5 @@
| ?- top_and_tail::test('Rosetta').
String with first character cut: osetta
String with last character cut: Rosett
String with first and last characters cut: osett
yes

View file

@ -0,0 +1,12 @@
/**********************************************************************
* 02.08.2013 Walter Pachl translated from REXX
**********************************************************************/
z = 'abcdefghijk'
l=z.length()
say ' the original string =' z
If l>=1 Then Do
Say 'string first character removed =' z.substr(2)
say 'string last character removed =' z.left(l-1)
End
If l>=2 Then
Say 'string first & last character removed =' z.substr(2,l-2)

View file

@ -0,0 +1,6 @@
var s = "The quick μ brown fox"
echo(s.substr(1))
echo(s.substr(0,s.len-2))
echo(s.substr(1,s.len-2))
# using slices
echo(s[1 .. -2])

View file

@ -1,3 +1,3 @@
println("knight" tail) // strip first character
println("socks" dropRight 1) // strip last character
println("brooms".tail dropRight 1) // strip both first and last characters
println("knight".tail) // strip first character
println("socks".init) // strip last character
println("brooms".tail.init) // strip both first and last characters