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
Use SysUtils.AdjustLineBreaks
first to normalize line breaks:
strText := AdjustLineBreaks(strText, tlbsCRLF);
strText := AnsiReplaceStr(strText, #13#10, '{\n}');
Another option is to use a TStringList
with its LineBreak
property:
function CleanText(strText : String) : String;
var
sl: TStringList;
begin
sl := TStringList.Create;
try
sl.Text := strText;
sl.LineBreak := '{\n}';
Result := sl.Text;
finally
sl.Free;
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With