I asked a similar question couple months ago. Thanks to Rob Kennedy I could load my whole text into a Richedit BUT I couldn't remove Null chars. I could load my text because I used Stream.
Now in this code:
var
strm : TMemorystream;
str : UTF8string;
ss : TStringstream;
begin
strm := tmemorystream.Create;
try
strm.LoadFromFile('C:\Text.txt');
setstring(str,PAnsichar(strm.Memory),strm.Size);
str := StringReplace(str, #0, '', [rfReplaceAll]); //This line doesn't work at all
ss := tstringstream.Create(str);
Richedit1.Lines.LoadFromStream(ss);
finally
strm.Free;
ss.Free;
end;
end;
I converted TMemorystream to string to remove Null Chars with StringReplace() and then converted it again to TStringstream to load it with Richedit.lines.LoadFromStream.
But my problem is that I can't remove Null Character using StringReplace(). I can replace other characters but not #0.
Is there any way to remove null charcters directly in TMemorystream and load it into a Richedit? How? If it's not possible or it's very complex, how can I remove them when I convert my text to string?
Thanks.
NULthen output it, else discard it 3) go to step 1.StringReplaceand link to another answer that accomplishes the same task.Content-Typeheader or in the HTML itself via a<meta>tag. You have to use the correct charset when decoding the data to Unicode. You can't load the data using whatever charset you feel like it. You will lose data that way.