Android Question How To Get Line String From .txt File

Sai Main Seng Kham

Member
Licensed User
Hi Again:)

I have a simple question for today
I have the (.txt) file in my RootDir
in the .txt file that will be have some text like this below

123456789
abcdefghijk
zzzzzzzz
I want to get the first line "123456789" as a string.
And similarly , i want to get the second line "abcdefghijk" as another string.
And the same way , i want to get the 3th line "zzzzzzz" as another string.

Please Reply to my post :)
thanks u.
 

Sai Main Seng Kham

Member
Licensed User
B4X:
    Dim txtlist As List = File.ReadList(File.DirAssets,"filetoread.txt")
    Dim str1 As String = txtlist.Get(0) ' Get 1st line
    Dim str2 As String = txtlist.Get(1) ' Get 2nd line
i mean the text file is not just 3 lines.

123456789
abcdefghijk
zzzzzzz
123456789
abcdefghijk
zzzzzzz
123456789
abcdefghijk
zzzzzzz
123456789
abcdefghijk
zzzzzzz
123456789
abcdefghijk
zzzzzzz
it can be non limited line
 

emexes

Well-Known Member
Licensed User
i mean the text file is not just 3 lines ... it can be non limited line
Putting a positive spin on it: now you have a choice of two solutions:

1/ Marco's suggestion will give you sequential (one-at-a-time) access to an unlimited number of lines
2/ Manfred's suggestion will give you random (direct, and in any order) access to a limited number of lines

and can use whichever works best for this particular task.
 
Last edited:
Top