On Tuesday, 22 March 2022 at 07:18:00 UTC, cc wrote:
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;
}
```

Oops, I misread what you were asking for. Was thinking quotes like quotation marks, not backslashes.

Reply via email to