delphi - Can't work with UTF-8 encoding -


i load text file using code (my file encoding utf-8) (how read text file contains 'null character' in delphi?):

uses ioutils;  var   s: string;   ss: tstringstream; begin   s := tfile.readalltext('c:\myfile.txt');   s := stringreplace(s, #0, '', [rfreplaceall]);  //removes null chars   ss := tstringstream.create(s);    try     richedit1.lines.loadfromstream(ss, tencoding.utf8); //utf8       ss.free;   end;  end; 

but problem richedit1 doesn't load whole text. it's not because of null characters. it's because of encoding. when run application code, loads whole text:

uses ioutils;  var   s: string;   ss: tstringstream; begin   s := tfile.readalltext('c:\myfile.txt');   s := stringreplace(s, #0, '', [rfreplaceall]);  //removes null chars   ss := tstringstream.create(s);    try     richedit1.lines.loadfromstream(ss, tencoding.default);       ss.free;   end;  end; 

i changed tencoding.utf8 tencoding.default. whole text loaded it's not in right format , it's not readable.

i guess there characters utf 8 doesn't support. loading process stops when want load char.

please help. workarounds?

****edit:**

i'm sure utf-8 , plain text. it's html source file. i'm sure has null charas saw them using notepad++ , value of richedit.plainext true

you should give encoding tfile.readalltext. after working unicode strings , don't have bother utf8 in richedit.

var   s: string; begin   s := tfile.readalltext('c:\myfile.txt', tencoding.utf8);   // shouldn't necessary    s := stringreplace(s, #0, '', [rfreplaceall]);  //removes null chars   richedit1.lines.text := s;  end; 

Comments