B4J Question Load text as UTF8 into TextArea

ThRuST

Well-Known Member
Licensed User
Longtime User
When loading a textfile into textarea the © sign (ALT+0169) does not display correctly when the textfile is loaded into textarea. I have tried different fonts but that did not solve the problem. Should UTF8 format be used when loading a textfile correctly? This is what I tried

Code: Copy
Sub ReadText
    
    Dim Te As String
    Te = File.ReadString(ApplicationPath, "Textfile.txt")
    Te.GetBytes("UTF8")
    TextArea.Text = Te
    
End Sub
 
1. Why do you dim the variable on one line and only set it on the second line?

2. The third line (TE.GetBytes) doesn't do anything useful.

Code: Copy
TextArea.Text = File.ReadString(ApplicationPath, "Textfile.txt")

File.ReadString expects UTF8 encoding. There are two possible causes:
1. The font doesn't include this sign (unlikely).
2. The text file encoding is not UTF8.
 
Upvote 0
Upvote 0
Here's a small source code example to support my question. Modify it and post your working solution.

Try hold ALT and type 0169 to get the © sign in the textarea. As you can see it shows, but not from the loaded textfile. It was saved as a textfile in Notepad on Windows 7.
 

Attachments

Last edited:
Upvote 0
My solution.

Open myText.txt in Notepad. Select File/Save As and change the encoding from ANSI to UTF8.

Capture.jpg

Capture.jpg
 
Upvote 0
I noticed that I saved the textfile with Wordpad as default, which have different options when saving files.
Thanks for bringing some clarity in this all of you.
 
Upvote 0
Back
Top