Printing a quoted string

Caten catenhu at gmail.com
Sun Mar 20 09:42:44 UTC 2022


On Sunday, 2 January 2022 at 21:16:55 UTC, Amit wrote:
> On Sunday, 2 January 2022 at 19:26:50 UTC, WebFreak001 wrote:
>> [...]
>
> On Sunday, 2 January 2022 at 19:37:38 UTC, JG wrote:
>> [...]
>
> Yes! That's what I needed.
>
> I wrapped it in a function like so:
>
> ```d
> string quote(string s) {
>     return format("%s", [s])[1 .. $ - 1];
> }
> unittest {
>     assert(quote("one \"two\"\nthree four") == `"one 
> \"two\"\nthree four"`);
> }
> ```
>
> Thanks for your responses ^_^

Hi, I also need a function to "unquote" string, like this:
```d
assert(unquote(`\n`)=="\n");
```
Is there a way to do that?


More information about the Digitalmars-d-learn mailing list