My app loads RTF-documents to a TextArea. All works properly, until I try to open a file with russian text. In that case, as line like “??? ???, ? ??? ???” suddenly looks like " , ".
The encoding of the TextArea is prompted as “2” equals UTF8, after I load the file to the TextArea. (TextArea1.Value.Encoding.Format.ToString)
Strangely, if I force-save the RTF-document in apple TextEdit to UTF8, suddenly the text appears correct in my TextArea. Must be some mismatch of encodings? How to find out what causes this? Thanks for any advice.
Maybe the textfile is not UTF8 encoded but something like Windows-1251?
That would explain why it works after you have saved the file with an UTF8 encoding.
[quote=478108:@Sascha S]Maybe the textfile is not UTF8 encoded but something like Windows-1251?
That would explain why it works after you have saved the file with an UTF8 encoding.[/quote]
Why would Xojo then tell me it is UTF8? Is there a trial and error procedure, to find out if that is the case?
t = TextInputStream.Open(f)
t.Encoding = Encodings.UTF8 // (Or any other fitting encoding)
TextArea1.StyledText.RTFData = t.ReadAll
Maybe it’ll work?[/quote]
Thanks, Sascha. That is the code I am using.
@Emile: I checked the headers of the documents:
{\rtf1\adeflang1025\ansi\ansicpg1251\uc1\adeff31507\deff0\… // <— this one is not working
{\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf600 // <— this one is working
Maybe Xojo is really miss-interpreting the RTF source. I’d report it via Feedback and in the meanwhile, maybe convert the RTF files using an external/shell tool to convert it to plain text before using it in your App?
On macOS you could do textutil -convert rtf test.txt. But i do not know if this is still valid for Catalina f.e…
Give the Forum a bit more time to help you solve it. The Devs are (most/all) all located in the US and will (wake up and) enter this Forum soon. I am sure, there are far more skilled people here which may be able to help you even better than Emile and i could.