Skip to content

Files with UTF-8 and BOM #345

Description

@ghelbere

Files with UTF8+BOM are not parsed, I had to include thhis in my code:
function LoadFileWithoutBOM(const FileName: string): string;
var
Bytes : TBytes;
Start : Integer;
begin
Bytes := TFile.ReadAllBytes(FileName);

Start := 0;
// UTF-8 BOM = EF BB BF
if (Length(Bytes) >= 3) and
(Bytes[0] = $EF) and
(Bytes[1] = $BB) and
(Bytes[2] = $BF) then
Start := 3;

Result := TEncoding.UTF8.GetString(Bytes, Start, Length(Bytes) - Start);
end;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions