Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
16
Task/String-matching/D/string-matching.d
Normal file
16
Task/String-matching/D/string-matching.d
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
void main() {
|
||||
import std.stdio;
|
||||
import std.algorithm: startsWith, endsWith, find, countUntil;
|
||||
|
||||
"abcd".startsWith("ab").writeln; // true
|
||||
"abcd".endsWith("zn").writeln; // false
|
||||
"abab".find("bb").writeln; // empty array (no match)
|
||||
"abcd".find("bc").writeln; // "bcd" (substring start
|
||||
// at match)
|
||||
"abab".countUntil("bb").writeln; // -1 (no match)
|
||||
"abab".countUntil("ba").writeln; // 1 (index of 1st match)
|
||||
|
||||
// std.algorithm.startsWith also works on arrays and ranges:
|
||||
[1, 2, 3].countUntil(3).writeln; // 2
|
||||
[1, 2, 3].countUntil([2, 3]).writeln; // 1
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue