toUTF16

Encodes the elements of s to UTF-16 and returns a newly GC allocated wstring of the elements.

wstring
toUTF16
(
S
)
(
S s
)

Parameters

s S

the range to encode

Return Value

Type: wstring

A UTF-16 string

Examples

import std.algorithm.comparison : equal;

// these graphemes are two code units in UTF-16 and one in UTF-32
assert("𤭢"d.length == 1);
assert("𐐷"d.length == 1);

assert("𤭢"d.toUTF16.equal([0xD852, 0xDF62]));
assert("𐐷"d.toUTF16.equal([0xD801, 0xDC37]));

See Also

For a lazy, non-allocating version of these functions, see byUTF.

Meta