Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,16 @@
String strOrig = 'brooms';
String str1 = strOrig.substring(1, strOrig.length());
system.debug(str1);
String str2 = strOrig.substring(0, strOrig.length()-1);
system.debug(str2);
String str3 = strOrig.substring(1, strOrig.length()-1);
system.debug(str3);
// Regular Expressions approach
String strOrig = 'brooms';
String str1 = strOrig.replaceAll( '^.', '' );
system.debug(str1);
String str2 = strOrig.replaceAll( '.$', '' ) ;
system.debug(str2);
String str3 = strOrig.replaceAll( '^.|.$', '' );
system.debug(str3);

View file

@ -0,0 +1,18 @@
#import <Foundation/Foundation.h>
int main()
autoreleasepool
s := 'knight'
Log( '%@', s[1 .. s.length-1] ) // strip first character
s = 'socks'
Log( '%@', s[0 .. s.length-2] ) // strip last character
s = 'brooms'
Log( '%@', s[1 .. s.length-2] ) // strip both first and last characters
s = 'Δημοτική'
Log( '%@', s[1 .. s.length-2] ) // strip both first and last characters
return 0

View file

@ -0,0 +1,11 @@
' FB 1.05.0 Win64
Dim s As String = "panda"
Dim s1 As String = Mid(s, 2)
Dim s2 As String = Left(s, Len(s) - 1)
Dim s3 As String = Mid(s, 2, Len(s) - 2)
Print s
Print s1
Print s2
Print s3
Sleep

View file

@ -0,0 +1,10 @@
local(str = 'The quick grey rhino jumped over the lazy green fox.')
// String with first character removed
string_remove(#str,-startposition=1,-endposition=1)
// String with last character removed
string_remove(#str,-startposition=#str->size,-endposition=#str->size)
// String with both the first and last characters removed
string_remove(string_remove(#str,-startposition=#str->size,-endposition=#str->size),-startposition=1,-endposition=1)

View file

@ -0,0 +1,10 @@
local(mystring = 'ÅÜÄÖカ')
#mystring -> remove(1,1)
#mystring
'<br />'
#mystring -> remove(#mystring -> size,1)
#mystring
'<br />'
#mystring -> remove(1,1)& -> remove(#mystring -> size,1)
#mystring

View file

@ -0,0 +1,13 @@
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

View file

@ -0,0 +1,4 @@
put "pple" into x
answer char 2 to len(x) of x // pple
answer char 1 to -2 of x // ppl
answer char 2 to -2 of x // ppl

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

@ -0,0 +1,4 @@
: topAndTail(s)
s right(s size 1-) println
s left(s size 1-) println
s extract(2, s size 1- ) println ;

View file

@ -0,0 +1,4 @@
constant s = "(test)"
?s[2..-1]
?s[1..-2]
?s[2..-2]

View file

@ -0,0 +1,4 @@
aString = "1Welcome to the Ring Programming Language2"
see substr(aString,2,len(aString)-1) + nl +
substr(aString,1,len(aString)-1) + nl +
substr(aString,2,len(aString)-2) + nl

View file

@ -0,0 +1,4 @@
say "knight".substr(1); # strip first character
say "socks".substr(0, -1); # strip last character
say "brooms".substr(1, -1); # strip both first and last characters
say "与今令".substr(1, -1); # => 今

View file

@ -0,0 +1,4 @@
var gstr = "J\x{332}o\x{332}s\x{332}e\x{301}\x{332}";
say gstr-/^\X/; # strip first grapheme
say gstr-/\X\z/; # strip last grapheme
say gstr.sub(/^\X/).sub(/\X\z/); # strip both first and last graphemes

View file

@ -0,0 +1,4 @@
let txt = "0123456789"
println(dropFirst(txt))
println(dropLast(txt))
println(dropFirst(dropLast(txt)))

View file

@ -0,0 +1,4 @@
let txt = "0123456789"
println(txt[txt.startIndex.successor() ..< txt.endIndex])
println(txt[txt.startIndex ..< txt.endIndex.predecessor()])
println(txt[txt.startIndex.successor() ..< txt.endIndex.predecessor()])

View file

@ -0,0 +1,3 @@
var txt = "0123456789"
txt.removeAtIndex(txt.startIndex)
txt.removeAtIndex(txt.endIndex.predecessor())

View file

@ -0,0 +1,55 @@
extension String {
/// Ensure positive indexes
private func positive(index: Int) -> Int {
if index >= 0 { return index }
return count(self) + index
}
/// Unicode character by zero-based integer (character) `index`
/// Supports negative character index to count from end. (-1 returns character before last)
subscript(index: Int) -> Character {
return self[advance(startIndex, positive(index))]
}
/// String slice by character index
subscript(range: Range<Int>) -> String {
return self[advance(startIndex, range.startIndex) ..<
advance(startIndex, range.endIndex, endIndex)]
}
/// Left portion of text to `index`
func left(index : Int) -> String {
return self[0 ..< positive(index)]
}
/// Right portion of text from `index`
func right(index : Int) -> String{
return self[positive(index) ..< count(self)]
}
/// From `start` index until `end` index
func mid(start: Int, _ end: Int) -> String {
return self[positive(start) ..< positive(end)]
}
}
let txt = "0123456789"
txt.right(1) // Right part without first character
txt.left(-1) // Left part without last character
txt.mid(1,-1) // Middle part without first and last character

View file

@ -0,0 +1,7 @@
"一二三四五六七八九十"[1:]' => "二三四五六七八九十"
"一二三四五六七八九十"[:-1]' => "一二三四五六七八九"
"一二三四五六七八九十"[1:-1]' => "二三四五六七八九"
"a"[1:-1] # => ""

View file

@ -0,0 +1 @@
"abc" | capture( ".(?<monkey>.*)." ).monkey => "b"