Recent

Author Topic: [SOLVED] CSVDocument and UTF-8 characters  (Read 1293 times)

lainz

  • Hero Member
  • *****
  • Posts: 4621
  • Web, Desktop & Android developer
    • https://lainz.github.io/
[SOLVED] CSVDocument and UTF-8 characters
« on: July 15, 2024, 05:49:43 pm »
Hi I'm using CSVDocument, and I can't read propery UTF-8 characters like áéíóúÁÉÍÓÜñÑ.

There's a way I can do this?
« Last Edit: July 15, 2024, 10:22:59 pm by lainz »

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
Re: CSVDocument and UTF-8 characters
« Reply #1 on: July 15, 2024, 06:25:05 pm »
If the characters in the document are truly utf8 and not encoded in any other ansi codepage?
simply make your strings utf8 and maybe also add {$codepage utf8} on top of your source  units. The latter is to interpret string literals in utf8 correctly.
Also note that if you are compiling for a terminal or console app, the codepage of te terminal must be utf8 too.
But the file may also have been encoded in a different code page, e.g. mid-european.
In that case, on Windows you sometimes need to use the provided conversion functions:
Code: Pascal  [Select][+][-]
  1. {$ifndef unix}
  2. initialization
  3.    SetMultiByteConversionCodePage(CP_UTF8);
  4. finalization
  5.    SetMultiByteConversionCodePage(CP_ACP);// system default
  6. {$endif}
« Last Edit: July 15, 2024, 06:37:17 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

lainz

  • Hero Member
  • *****
  • Posts: 4621
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: CSVDocument and UTF-8 characters
« Reply #2 on: July 15, 2024, 10:22:41 pm »
simply make your strings utf8 and maybe also add {$codepage utf8} on top of your source  units.

Thanks Thaddy. Solved!

 

TinyPortal © 2005-2018