Android Question To read txt file with more fields

Giusy

Active Member
Licensed User
Hi,
I read a txt file with strLines = tr.ReadLine, bt.Text = strLines
but this command works if only one field exists.

Now my txt is composed of several fields, registered as follows:
"001","ABCDEF"
"002","XXXXXXXXXXXX"
How can i read them?
Thank you
 

Giusy

Active Member
Licensed User
Hi @Erel

In fact, this night, after much research, on the forum, I found the solution. I loaded the library StringUtils and wrote this code:

B4X:
Dim su As StringUtils
    Dim taggax(10) As String
    Dim descx(10) As String
    Dim tot As Int
    tot=1
    For Each Row() As String In su.LoadCSV (File.DirAssets, "myfile.txt",",")
        descx(tot)=Row(0)
        taggax(tot)=Row(1)
        tot=tot+1
    Next
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Whenever I have files in my apps that have key/value pairs (eg: settings files) I always create a map then use File.ReadMap2 & File.WriteMap.

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
KVS2 is much better than File.WriteMap / ReadMap as a key value store. ReadMap / WriteMap create a text file so they only support simple types.
Yep - I use KVS2 as well, but for simple text files with key/value pairs I use ReadMap & WriteMap - partly because I have a standard settings class that I use in all my apps & I can't be bothered rewriting it!

- Colin.
 
Upvote 0
Top