size of a string in bytes
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jan 28 07:54:04 PST 2017
On Sat, Jan 28, 2017 at 03:32:33PM +0000, Nestor via Digitalmars-d-learn wrote:
[...]
> I do not want string lenth or code points. Perhaps I didn't explain
> myselft.
The .length property of a string is the number of bytes used to store
the string.
> 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).
What you call "string length" is called grapheme count in D. What you
want is the .length property.
The number of bytes in a UTF-8 string is the same thing as the number of
code units (note: do not confuse with code points, which is something
else).
--T
More information about the Digitalmars-d-learn
mailing list