Android Question Read file encode in ANSI

guenneguez_t

Member
Licensed User
Longtime User
Hi,

I want to load a file encode in ANSI and use data to populate Spinner.
There is a charactère with accent.
Join a sample file.
How can I do ?

Regard's
Thomas
 

Attachments

  • EPREUVE.txt
    265 bytes · Views: 268

klaus

Expert
Licensed User
Longtime User
1. Change the encoding to URF-8, if this file is only one original file which you don't reuse as it is.
You can di it with notapad++.

2. You can use TextReader with TextReader.Initialize2(File.OpenInput(File.DirAssets, "EPREUVE.txt", "Windows-1252").
Then you can :
- Read the whole text with TextReader.ReadAll
- Read line by line with TextReader.ReadLine, something like this:
B4X:
Private txr As TextReader
txr.Initialize2(File.OpenInput(File.DirAssets, "EPREUVE.txt"), "Windows-1252")
Private line As String
line = txr.ReadLine
Do While line <> Null
    Log(line)
    line = txr.ReadLine
 Loop
- Read a List with TextReader.ReadList
Be aware that if you need to save the file again with ANSI you would need to use TextWriter.

This is explained in the B4X Basic Language booklet chapter 4.12.6 Text encoding.
Et c'est aussi expliqué en français dans le livret B4X Langage Basic chapitre 4.12.6 Encodage de texte.
 
Last edited:
Upvote 0
Top