View source code Display the source code in std/encoding.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.encoding.transcode

Convert a string from one encoding to another.

Prototype

void transcode(Src, Dst)(
  immutable(Src)[] s,
  immutable(Dst)[] r
);

Supersedes

This function supersedes std.utf.toUTF8(), std.utf.toUTF16() and std.utf.toUTF32() (but note that to!() supersedes it more conveniently).

Standards

Unicode 5.0, ASCII, ISO-8859-1, ISO-8859-2, WINDOWS-1250, WINDOWS-1252

Parameters

NameDescription
s Source string. Must be validly encoded. This is enforced by the function's in-contract.
r Destination string

See Also

std.conv.to

Example

wstring ws;
// transcode from UTF-8 to UTF-16
transcode("hello world",ws);
assert(ws == "hello world"w);

Latin1String ls;
// transcode from UTF-16 to ISO-8859-1
transcode(ws, ls);
assert(ws == "hello world");

Authors

Janice Caron

License

Boost License 1.0.

Comments