Search code examples
delphireplaceline-breaks

delphi: replace line breaks in a string, which is filled out of an varchar2 field (oracle), while writing a textfile


I am executing a sql-statement on a oracle database and writing the results into a textfile. A field, called "targets" (varchar2) has line breaks in it.

Until now i replaced the line breaks like this:

function CleanText(strText : String) : String;
var
  ii: integer;
begin
  for ii := 1 to Length(strText) do
    if strText[ii] < chr(32) then strText[ii] := ' ';
  end;

  Result := strText;
end;

But now i want to replace the line breaks with a specific string: "{\n}". I tried different things like:

strText := AnsiReplaceStr(strText, #13#10, '{\n}');

But it doesnt work. There a no "{\n}" in the written textfile.

I copy pasted an example string out of the sql-statement:

"1) Sicherung der Liquidität der Stadt XYZ durch:'#$A'- exakte Buchführung zur Sicherung des korrekten Ausweises der Forderungen / Verbindlichkeiten"

I could do something like this (but i think, that's not a good solution):

strText := AnsiReplaceStr(strText, '''#$A''', '{\n}');

Do you have any ideas?

Regards, Dennis


Solution

  • Use SysUtils.AdjustLineBreaks first to normalize line breaks:

    strText := AdjustLineBreaks(strText, tlbsCRLF);
    strText := AnsiReplaceStr(strText, #13#10, '{\n}');