Today's programming challenge - How's your Range-Fu ?

JohnnyK via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 21 06:06:21 PDT 2015


On Monday, 20 April 2015 at 19:24:01 UTC, Panke wrote:
> On Monday, 20 April 2015 at 18:03:50 UTC, John Colvin wrote:
>> On Monday, 20 April 2015 at 17:48:17 UTC, Panke wrote:
>>> To measure the columns needed to print a string, you'll need 
>>> the number of graphemes. (d|)?string.length gives you the 
>>> number of code units.
>>
>> Even that's not really true.
>
> Why? Doesn't string.length give you the byte count?

I think what you are looking for is string.sizeof?

 From the D reference

.sizeof	Returns the array length multiplied by the number of 
bytes per array element.
.length	Returns the number of elements in the array. This is a 
fixed quantity for static arrays. It is of type size_t.


Isn't a string type an array of characters (char[] string UTF-8, 
wchar[] string UTF-16, and dchar[] string UTF-32) and not 
arbitrary bytes?


More information about the Digitalmars-d mailing list