Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
60
Task/Substring/Ecstasy/substring.ecstasy
Normal file
60
Task/Substring/Ecstasy/substring.ecstasy
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
module Substrings {
|
||||
void run(String[] args = []) {
|
||||
@Inject Console console;
|
||||
if (args.size < 4) {
|
||||
console.print(
|
||||
$|
|
||||
|Usage:
|
||||
|
|
||||
| xec Substrings <str> <offset> <count> <substr>
|
||||
|
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
String s = args[0];
|
||||
Int n = new Int(args[1]);
|
||||
Int m = new Int(args[2]);
|
||||
String sub = args[3];
|
||||
Char c = sub[0];
|
||||
|
||||
console.print($|
|
||||
|{s .quoted()=}
|
||||
|{substring(s, n, m ).quoted()=}
|
||||
|{substring(s, n ).quoted()=}
|
||||
|{substring(s ).quoted()=}
|
||||
|{substring(s, c, m ).quoted()=}
|
||||
|{substring(s, sub, m).quoted()=}
|
||||
|
|
||||
);
|
||||
}
|
||||
|
||||
// starting from n characters in and of m length
|
||||
static String substring(String s, Int n, Int m) {
|
||||
assert 0 <= n <= n+m;
|
||||
return n < s.size ? s[n..<(n+m).notGreaterThan(s.size)] : "";
|
||||
}
|
||||
|
||||
// starting from n characters in, up to the end of the string
|
||||
static String substring(String s, Int n) {
|
||||
assert 0 <= n;
|
||||
return s.substring(n);
|
||||
}
|
||||
|
||||
// whole string minus the last character
|
||||
static String substring(String s) {
|
||||
return s.size > 1 ? s[0..<s.size-1] : "";
|
||||
}
|
||||
|
||||
// starting from a known character within the string and of m length
|
||||
static String substring(String s, Char c, Int m){
|
||||
assert 0 <= m;
|
||||
return substring(s, s.indexOf(c) ?: 0, m);
|
||||
}
|
||||
|
||||
// starting from a known substring within the string and of m length
|
||||
static String substring(String s, String sub, Int m){
|
||||
assert 0 <= m;
|
||||
return substring(s, s.indexOf(sub) ?: 0, m);
|
||||
}
|
||||
}
|
||||
13
Task/Substring/PascalABC.NET/substring.pas
Normal file
13
Task/Substring/PascalABC.NET/substring.pas
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{$zerobasedstrings}
|
||||
const
|
||||
n = 3;
|
||||
m = 2;
|
||||
|
||||
begin
|
||||
var s := '0123456789';
|
||||
Writeln(s.Substring(n, m));
|
||||
Writeln(s[n:]);
|
||||
Writeln(s[:^1]);
|
||||
Writeln(s.Substring(s.IndexOf('3'), m));
|
||||
Writeln(s.Substring(s.IndexOf('456'), m));
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue