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

B4X:
Sub ReadText
    
    Dim Te As String
    Te = File.ReadString(ApplicationPath, "Textfile.txt")
    Te.GetBytes("UTF8")
    TextArea.Text = Te
    
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
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.

B4X:
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

ThRuST

Well-Known Member
Licensed User
Longtime User
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

  • ReadString01.zip
    15.1 KB · Views: 213
Last edited:
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
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

ThRuST

Well-Known Member
Licensed User
Longtime User
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
Top