How to add a CR/LF pair (new line) to the end (or middle) of a string in Delphi?
Code://CR = #13 and LF = #10
'line1' + #13#10 +'line2';
The line termination character sequence is operating system dependent - CRLF (Windows/MS DOS), LF (Unix) and CR (Macintosh). As a result, moving text files between systems without conversion can cause pretty severe problems, eg. Notepad just shows the Unix terminators as boxes. See the following snippets for the conversion.
Code:const
strLineBreak = {$IFDEF LINUX} AnsiChar(#10) {$ENDIF}
{$IFDEF MSWINDOWS} AnsiString(#13#10) {$ENDIF};
Code:strNew := stringreplace(oldstring, string_or_character_to_replace, string_or_character_to_replace_with, [rfreplaceall]);
example:
strNewData := stringreplace(strOldData, #10, #13#10, [rfreplaceall]);
Related:
Newline in other programming languages
C\C++ - "\n";
VisualBasic - vbNewLine;
Java - newLine().