Tutorial by Examples

string is defined as alias string = immutable(char)[];: so need to use dup to make a mutable char array, before it can be reversed: import std.stdio; import std.string; int main() { string x = "Hello world!"; char[] x_rev = x.dup.reverse; writeln(x_rev); // !dlr...
Empty string Empty string is not null but has zero length: string emptyString = ""; // an empty string is not null... assert(emptyString !is null); // ... but it has zero lenght assert(emptyString.length == 0); Null string string nullString = null; a null string is null (De ...
String to immutable ubyte[] string s = "unogatto"; immutable(ubyte[]) ustr = cast(immutable(ubyte)[])s; assert(typeof(ustr).stringof == "immutable(ubyte[])"); assert(ustr.length == 8); assert(ustr[0] == 0x75); //u assert(ustr[1] == 0x6e); //n assert(ustr[2] == 0x6f); //o...

Page 1 of 1