Android Question Special Character Decoding Reading txt file.

Chianca

Member
Licensed User
Longtime User
Hello, I have a text file that contains some lines and special characters words like "CAFÉ".

When I'm using de code below, the words that contains special characters returns with other characters, like "CAF■".

B4X:
dim FileReaderList as List
    FileReaderList.initialize
FileReaderList = File.ReadList(File.DirAssets,"MyFile.txt")
msgbox(FileReaderList.get(0),"")

The original line inside the .txt file is: "0001 CAFÉ SÃO BRAZ"
The return is: "0001 CAF• S¬O BRAZ"

NOTE:. These characters used to show the return (• and ¬) are symbolic.
 

Luis Miguel T. Martins

Member
Licensed User
Longtime User
this work, thanks Erel :)

B4X:
Dim lines As List
Dim tr As TextReader

...

Sub lingua(l_number As Int) As String
l_number=l_number-1
tr.Initialize2(File.OpenInput(File.DirDefaultExternal, "english.txt"), "ISO-8859-1")
lines = tr.ReadList
tr.Close

'return the line text with ç á ü ƒ etc

Return(lines.Get(l_number))

End Sub
 
Last edited:
Upvote 0

James Chamblin

Active Member
Licensed User
Longtime User
Glad you found a solution, but I would suggest making a couple small changes. No need to read the file again every time you need to access a line.
B4X:
Dim lines As List
Dim tr As TextReader
...

Sub lingua(l_number As Int) As String
    l_number=l_number-1
    If lines.isInitialized = False Then
        tr.Initialize2(File.OpenInput(File.DirDefaultExternal, "english.txt"), "ISO-8859-1")
        lines = tr.ReadList
        tr.Close
    End If

    'return the line text with ç á ü ƒ etc

    Return(lines.Get(l_number))

End Sub
 
Upvote 0
Top