D has two ways to declare WYSIWYG strings:
r"thestring"
`thestring`
So, the following program
import std.stdio;
void main()
{
auto a = r"hello\nworld";
auto b = `hello\nworld`;
writeln(a);
writeln(b);
}
prints
hello\nworld
hello\nworld
However, if you have an arbitrary string rather than a string literal, and you want to be able to print it with the newlines and whatnot being printed as their escape sequences, you're going to have to do some string processing - likely using std.string.replace()
to replace each character with its escape sequence with the extra backslashes. For instance, to escape the newlines, you'd do this:
str.replace("\n", "\\n");
But you'd have to do that individually for '\t', '\r', '\', etc. I'm not aware of any way to do it automatically. The WYSIWYG strings just let you avoid having to using all of the extra backslashes when constructing the string.