I'm using Lazarus IDE v1.4.4
Here's my Code,
It seems that it worked for txt, (didnt realize it b4)
but when it is .csv and opened by Microsoft Office Excel,
'中學部' turns into '銝剖飛??'
procedure AddData;
var Data:TextFile;
begin
assign(Data,'Data.csv');
rewrite(Data);
write(Data,'中學部');
Closefile(Data)
end;
That's an Excel bug (or feature). It considers the csv file encoding to have the same encoding as your system (which is not true, your system has an ansi encoding, while the file is UTF8).
A workaround is to use UTF16LE encoding with BOM marker.
Edit:
Simple test:
uses
LazUTF8,...;
...
procedure AddData;
var Data:File;
s: String;
ss: WideString; { or UnicodeString }
begin
assign(Data,'Data.csv');
rewrite(Data);
Reset(Data, 1);
BlockWrite(Data, #$FF#$FE, 2); { Write BOM marker }
s := '中學部'; { UTF8 }
ss := s; { or ss := UTF8ToUTF16(s); } { UTF16 }
BlockWrite(Data, ss[1], Length(RawByteString(ss)));
Closefile(Data)
end;
Thx for advice
it seems that it is the default encoding problem
so I changed the default encoding of my system to UTF8
and it worked fine now
btw when I use ur program,
It shows Identifier not found "RawByteString",
is anything missing?