Reputation: 43
I am using Delphi 7 and have a routine which takes a csv file with a series of records and imports them. This is done by loading it into a TStringList with MyStringList.LoadFromFile(csvfile) and then getting each line with line = MyStringList[i].
This has always worked fine but I have now discovered that special characters are not picked up correctly. For example, Rue François Coppée comes out as Rue François Coppée - the accented French characters are the problem.
Is there a simple way to solve this?
Upvotes: 3
Views: 3124
Reputation: 613572
Your file is encoded as UTF-8. For instance consider the ç. As you can see from the link, this is encoded in UTF-8 as 0xC3 0xA7
. And in Windows-1252, 0xC3
encodes à and 0xA7
encodes §
.
Whether or not you can handle this easily using your ANSI Delphi depends on the prevailing code page under which your program runs.
UTF8Decode
.string
variable which is encoded using the prevailing ANSI charset. If this is the case then you need to use Unicode.If you care about handling international text then you need to either:
WideString
and the TNT Unicode components.Upvotes: 4
Reputation: 2799
Probably it's not in UTF8 encoding. Try to convert it:
Text := UTF8Encode(Text);
Regards,
Upvotes: 1