The valid code is option #1:
-
Memo1.Lines.Add(Format('1: %s' + ^M + '2: %s', [Edit1.Text, Edit2.Text]);
^M is a Delphi code construct that compiles, but I haven't found it documented anywhere. The ^M is character - analogue to #13#10 (or \n in c parlance). The + operators aren't even necessary. You can do 'string1'^M'string2' and get the same result.
I wouldn't encourage using this in code, but it's good to know that it exists.
5 Comments
When you open the command line and press Ctrl+Z, you see ^Z displayed, which is how DOS represented the End of File character, #26.
Similarly, M is character 13 in the alphabet and ^M in both Delphi and DOS is equivalent to #13. You can follow the pattern: ^G or #7 is the bell character, ^H or #8 is backspace and ^I or #9 is tab.
So while you could use #number to access any ASCII code, ^A-^Z accesses the non-printable characters #1 to #26 and any of those should work in Delphi.
Now, does anyone know if there are equivalent forms for non-printable characters #27 through to #31?
actually ^M is #13 (CR = Carrier Return)
in windows to mark new line usually CR LF(#10, Line Feed) symbol combination is used. In unix usually only LF is used.
CR will work in most situations but for example some text editors won’t recognize CR alone as line break.
Oh and btw ‘\n’ stands for LF, ‘\r’ = CR in C
As said above, ^M does *NOT* equal CRLF but only CR. The fact that it *displays* properly is only a side effect.
You can probably test that easily by checking the string length and/or by running through the whole string and checking for the presence (or not) of a LF character.
BTW: I’m un-subscribing this feed. The idea is nice, but the implementation has been very lacking: if you’re not willing to put in the extra effort to validate your claims and exercises, then I’m too busy to read it.
Nothing personal, but if you want people to read, you might as well double-check everything before actually posting.
Best of luck to you,
Fernando Madruga
Fernando, you may not read this, but I disagree with you. Jacob may had had mistakes in some of the puzzles he posted, but the discussion of those is often just as useful as the solutions to the puzzles.
In the “Roles and Goals” puzzle, for example, I learned that you can assign one TStrings to another and it does a Assign() behind the scenes. From Ray Konopka, no less!
I applaud Jacob’s work, and hope that he keeps it up.
One Trackback/Pingback
Best home video sex….
Home made sex video. Upload your home made video sex. Free home sex video sharing….
Post a Comment