February 27, 2019 [your code here] | ||||
---|---|---|---|---|
| ||||
void main() { import std.stdio : writefln; int[char[2]] aa; auto arr = "ABBBA"; // Iterate over all pairs in the string and observe each pair // ('A', 'B'), ('B', 'B'), ('B', 'A'), ... // String slicing doesn't allocate a copy foreach (i; 0 .. arr.length - 1) aa[arr[i .. $][0 .. 2]]++; foreach (key, value; aa) writefln("key: %s, value: %d", key, value); |
Copyright © 1999-2021 by the D Language Foundation