Random string samples & unicode

bearophile bearophileHUGS at lycos.com
Sat Sep 11 06:42:09 PDT 2010


> There randomCover() doesn't work with a string, a dstrings or with a char[].
> If later you need to process that res dchar[] with std.string you will have troubles.

The problems are more widespread, this is a simple generator of terms of the "look and say" sequence (to generate a member of the sequence from the previous member, read off the digits of the previous member, counting the number of digits in groups of the same digit: http://en.wikipedia.org/wiki/Look_and_say_sequence ):


import std.stdio, std.conv, std.algorithm;

string lookAndSay(string input) {
    string result;
    foreach (g; group(input))
        result ~= to!string(g._1) ~ (cast(char)g._0);
    return result;
}

void main() {
    string last = "1";
    writeln(last);
    foreach (i; 0 .. 10) {
        last = lookAndSay(last);
        writeln(last);
    }
}


I was not able to remove that cast(char), even if I replace all strings in that program with dstrings.
Is someone else using D2?

Bye,
bearophile


More information about the Digitalmars-d mailing list