Printing a quoted string

cc cc at nevernet.com
Tue Mar 22 07:18:00 UTC 2022


On Sunday, 20 March 2022 at 09:42:44 UTC, Caten wrote:
> Hi, I also need a function to "unquote" string, like this:
> ```d
> assert(unquote(`\n`)=="\n");
> ```
> Is there a way to do that?

I rolled my own for that recently:
```d
string dequote(string str) @safe pure {
	if (str.length < 2)
		return str;
	if ((str[0] == '"' || str[0] == '\'' || str[0] == '`') && 
str[$-1] == str[0]) {
		return str[1 .. $-1];
	}
	return str;
}
```


More information about the Digitalmars-d-learn mailing list