Author Topic: Charset conversions  (Read 3986 times)

Rodrigo Robles

  • New Member
  • *
  • Posts: 30
Charset conversions
« on: September 14, 2011, 02:56:15 am »
Hi friends,

I'm loading an ANSI TXT file into a TStringList and want to show some data in a TEdit. I have some extended ASCII chars into the file, but TEdit doesn't show these chars, even if I try converting it using AnsiToUtf8.
I wrote this short code to show what happens:

  SetLength(Str,50);
  AssignFile(FileVar,'teste2.txt');
  Reset(FileVar,47);
  Seek(FileVar,2);
  BlockRead(FileVar,Buf,1);
for c := 1 to 47 do
  Str[c] := Chr(Buf[c]);
  Label1.Caption := AnsiToUTF8(Str);
  CloseFile(FileVar);

The character 'ã' are shown as '?'. If I don't use AnsiToUTF8, just shows a crossed block.
What should be the right way to do it?

The file 'teste2.txt' follows attached.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Charset conversions
« Reply #1 on: September 14, 2011, 08:07:49 am »
Have you tried SysToUTF8 or even other way around (for some reason) UTF8ToSys?

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: Charset conversions
« Reply #2 on: September 14, 2011, 08:29:02 am »
On Windows it works fine.   Are you on Linux or Mac?

You might consider converting your file to UTF8 already.

On *NIX machines (Unix, Linux, Mac)  that is done on  the command line with the "iconv" tool.
« Last Edit: September 14, 2011, 08:32:24 am by Arbee »
1.0/2.6.0  XP SP3 & OS X 10.6.8

 

TinyPortal © 2005-2018