View source code
Display the source code in std/string.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

Function std.string.representation

Returns the representation of a string, which has the same type as the string except the character type is replaced by ubyte, ushort, or uint depending on the character width.

auto representation(Char) (
  Char[] s
) pure nothrow @nogc @safe
if (isSomeChar!Char);

Parameters

NameDescription
s The string to return the representation of.

Returns

The representation of the passed string.

Example

string s = "hello";
static assert(is(typeof(representation(s)) == immutable(ubyte)[]));
assert(representation(s) is cast(immutable(ubyte)[]) s);
writeln(representation(s)); // [0x68, 0x65, 0x6c, 0x6c, 0x6f]

Authors

Walter Bright, Andrei Alexandrescu, Jonathan M Davis, and David L. 'SpottedTiger' Davis

License

Boost License 1.0.