Re: How to escape control characters?

2024-09-22 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 19 September 2024 at 14:30:08 UTC, Gerardo Cahn wrote: On Wednesday, 24 August 2022 at 08:12:33 UTC, Salih Dincer wrote: On Tuesday, 23 August 2022 at 23:17:21 UTC, Salih Dincer wrote: ... Actually, both structures could be combined: ```d struct EscapedString { string[1] str;

Re: How to escape control characters?

2024-09-20 Thread kdevel via Digitalmars-d-learn
On Thursday, 19 September 2024 at 14:30:08 UTC, Gerardo Cahn wrote: I am using the code listed here. It should be left to posterity that the code presented in this thread cannot properly escape ``` "A\xfeZ" ``` ``` BV's escape: cast(char) 0x41, cast(char) 0xFE, cast(char) 0x5A steve's: c

Re: How to escape control characters?

2024-09-19 Thread Gerardo Cahn via Digitalmars-d-learn
On Wednesday, 24 August 2022 at 08:12:33 UTC, Salih Dincer wrote: On Tuesday, 23 August 2022 at 23:17:21 UTC, Salih Dincer wrote: ... Actually, both structures could be combined: ```d struct EscapedString { string[1] str; this(string str) @nogc pure nothrow @safe { ...(rest clipped) `

Re: How to escape control characters?

2022-08-24 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 23 August 2022 at 23:17:21 UTC, Salih Dincer wrote: The nice thing here is that you can change the format specifiers as you wish. Actually, both structures could be combined: ```d struct EscapedString { string[1] str; this(string str) @nogc pure nothrow @safe { this

Re: How to escape control characters?

2022-08-23 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 23 August 2022 at 13:09:01 UTC, Steven Schveighoffer wrote: Without allocations. This took me longer than I had hoped it would. It needs the 1-char buffer to avoid sending the surrounding quotes. Surely what Steve does is better. But for some reason I like simple and useful things

Re: How to escape control characters?

2022-08-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/23/22 6:09 AM, Bastiaan Veelo wrote: On Thursday, 31 March 2016 at 03:15:49 UTC, cy wrote: This might be a dumb question. How do I format a string so that all the newlines print as \n and all the tabs as \t and such? The easiest is this: ```d import std.conv; string str = `Hello "World"

Re: How to escape control characters?

2022-08-23 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 31 March 2016 at 03:15:49 UTC, cy wrote: This might be a dumb question. How do I format a string so that all the newlines print as \n and all the tabs as \t and such? The easiest is this: ```d import std.conv; string str = `Hello "World" line 2`; writeln([str].text[2..$-2]); // He

Re: How to escape control characters?

2016-03-30 Thread cy via Digitalmars-d-learn
Oh, cool. On Thursday, 31 March 2016 at 03:29:19 UTC, H. S. Teoh wrote: Or implement manual substitution with a pipeline: string myString = ...; string escapedStr = myString .chunks(1) .map!(c => (c == "\n") ? "\\n" : (c

Re: How to escape control characters?

2016-03-30 Thread cy via Digitalmars-d-learn
On Thursday, 31 March 2016 at 03:23:52 UTC, Seb wrote: http://dlang.org/spec/lex.html#WysiwygString r"ab\n" or `ab\n` Yes I know. But I mean like, string a = r"ab\n"; writeln(escape(a)); // => ab\n

Re: How to escape control characters?

2016-03-30 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 31, 2016 at 03:23:52AM +, Seb via Digitalmars-d-learn wrote: > On Thursday, 31 March 2016 at 03:15:49 UTC, cy wrote: > >This might be a dumb question. How do I format a string so that all > >the newlines print as \n and all the tabs as \t and such? > > http://dlang.org/spec/lex.htm

Re: How to escape control characters?

2016-03-30 Thread Seb via Digitalmars-d-learn
On Thursday, 31 March 2016 at 03:15:49 UTC, cy wrote: This might be a dumb question. How do I format a string so that all the newlines print as \n and all the tabs as \t and such? http://dlang.org/spec/lex.html#WysiwygString r"ab\n" or `ab\n`

How to escape control characters?

2016-03-30 Thread cy via Digitalmars-d-learn
This might be a dumb question. How do I format a string so that all the newlines print as \n and all the tabs as \t and such?