How can I remove all CRLF from a from a Base64 text file to make its content only on one line?
The following code uses a function, NoLineFeed, and a combination of TStringStream and AnsiString but still some CRLF are present (near the end of the file) after the content of the file have been processed by NoLineFeed.
function NoLineFeed was excerpted from a StackOverflow post by Arnaud Bouchez: Make String into only 1 line
var
StringVal: AnsiString;
XmlFile: TStringStream;
begin
XmlFile := TStringStream.Create;
try
XmlFile.LoadFromFile('file.txt');
StringVal := NoLineFeed(XmlFile.DataString);
if Length(StringVal) > 0 then
XmlFile.Write(StringVal[1], Length(StringVal));
XmlFile.SaveToFile('converted_file.txt');
finally
XmlFile.Free;
end;
end;
{ Arnaud Bouchez }
function NoLineFeed(const s: string): string;
var i: integer;
begin
result := s;
for i := length(result) downto 1 do
if ord(result[i])<32 then
if (i>1) and (ord(result[i-1])<=32) then
delete(result,i,1) else
result[i] := ' ';
end;