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.
 

DonManfred

Expert
Licensed User
Longtime 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
 
Upvote 0

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
 
Upvote 0

emexes

Expert
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:
Upvote 0
The given Sub is ideal example. Because it is even possible to add textual content to The texts of A GUI widgets with no need to manually add 30 or 40 textual descriptions for every GUI widget inside source code or by using GUI designer. Thank you for this perfect SUB. I will be finally able to automatize my verbal based tests for memory training. So very well done, perfect sub and sub even detect if The end of text file have been reached. Really. I have never found so ammazing programmers community like here is.
 
Upvote 0
Top