B4J Question [SOLVED] Reading ANSI text files with greek inside (get ??????)

Magma

Expert
Licensed User
Longtime User
Hi there,

i have to read some text files but file.readlist returns ????? where are greek letters..

Is there any ansi2utf sub routine ?

example in file:
Auerswald LAN TAPI 20 - Διεύθυνση 0

When output to combolist get that:
ansi.png

Thanks in advance.
 

Magma

Expert
Licensed User
Longtime User
My friend DonManfred look the files uploaded ... i uploaded at 984bytes - you uploaded at 1.2KB ...

The file is making by vb6-program using tapi and reading all tapi and writing to text... ANSI... i need to convert it automatically with code in utf-8.. not with notepad++
(i know the tool)

ansi.png


this picture is from combo in b4j
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
@DonManfred hope there is a technique to encode at utf8 needed by b4j.

Do you have for example Microsoft Excel - try to open using Windows (ANSI) or... 1253: Greek (Windows) or.... 1252: Western Europe (Windows)...

As i remeber the vb6 standard output ansi-1252... so is a must to convert ansi 2 utf...


I´ve loaded your file with notpad++ and it does not recognize it do be ANSI.


As i can remember notepad++ automatically convert to readable format.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I don't think you can read it as a list, you need to read it with File.OpenInput and inputstream into a buffer.
It is then simple to use BytesToString and specify encoding as cp1252, to get the correct characters.
You can then split it on crlf into an array, which you can put in a list.
eg:
B4X:
...
Dim inp As InputStream
Dim s_in As String
inp = File.OpenInput("","c:/temp/tapis.txt")
Dim b As Int
Dim my_buf(inp.BytesAvailable) As Byte
b = inp.ReadBytes(my_buf,0,inp.BytesAvailable)
inp.Close
s_in = BytesToString(my_buf,0,b,"cp1252") ' might be cp1253
Dim lines() As String
lines = Regex.Split(CRLF,s_in) ' you can add lines to a list if required after this line
For Each line As String In lines
Log(line)
Next
...

** cp1252 may need to be cp1253 - not sure which matches your output
 
Last edited:
Upvote 0
Top