Android Question How to save textfiles in UTF-8 format

ThRuST

Well-Known Member
Licensed User
Longtime User
I noticed that when saving a textfile on my Android device with B4A and sends it as an email attachment it is not showing properly in notepad. Each newline (CRLF or Chr(10) in EditText is not recognized in Windows notepad. It works correctly in B4i when doing the same thing. Seems like the char format needs to be specified when saving on Android but how to do that?
I used this code to save the text which looks correctly on Android but not on Windows:

Save:
File.WriteString(File.DirRootExternal, "mytextfile.txt", EditText1.Text)

Load:

EditText1.Text = File.ReadString(File.DirRootExternal, "mytextfile.txt")

B4X is great. Please also offer B4W (Windows phone)


Erel you're great. Microsoft should better buy your company :)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
File.WriteString saves the text encoded with UTF8. The problem is with Notepad. Don't use it. Use a proper text editor such as Notepad++ that can handle Linux / Android / Mac end of line character.

If you must use Windows end of line:
B4X:
File.WriteString(..., EditText1.Text.Replace(Chr(10), Chr(13) & Chr(10)))
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
That line of code up there... is nothing but brilliant. Pure genious - Now why didn't I think of that myself!!!! :eek:
Thank you Grand master Erel Yet again you bring peace in the dojo with your coding kung fu, thanks :)
 
Upvote 0
Top