On Saturday, 28 January 2017 at 15:32:33 UTC, Nestor wrote:
I want to know variable size in memory. For example, say I have an UTF-8 string of only 2 characters, but each of them takes 2 bytes. string length would be 2, but the content of the string would take 4 bytes in memory (excluding overhead for type size).

As said, the byte count is indeed string.length.
The number of code points can be found by std.range.walkLength, but be aware it takes O(answer) time to compute.

Example:

-----
import std.range, std.stdio;
void main () {
        auto s = "Привет!";
        writeln (s.length); // 13 bytes
        writeln (s.walkLength); // 7 code points
}
-----

Ivan Kazmenko.

Reply via email to