Logo

Programming-Idioms

History of Idiom 41 > diff from v33 to v34

Edit summary for version 34 by programming-idioms.org:
[D] Var name s

Version 33

2017-11-19, 03:53:27

Version 34

2018-01-03, 23:23:20

Idiom #41 Reverse a string

Create string t containing the same characters as string s, in reverse order.
Original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.

Illustration

Idiom #41 Reverse a string

Create string t containing the same characters as string s, in reverse order.
Original string s must remain unaltered. Each character must be handled correctly regardless its number of bytes in memory.

Illustration
Imports
import std.range, std.array;
Imports
import std.range, std.array;
Code
auto t = "The key to learning D is to 脚踏实地".retro.array;
Code
auto t = s.retro.array;
Comments bubble
Note, t is now a dchar[], which is a utf-32 encoded string. To convert back to the type of s, you need to call std.conv.to.
Comments bubble
Note, t is now a dchar[], which is a utf-32 encoded string. To convert back to the type of s, you need to call std.conv.to.
Demo URL
http://dpaste.dzfl.pl/b21510935840
Demo URL
http://dpaste.dzfl.pl/b21510935840