www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [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);
Feb 27