Android Question Get some parts data from a list(ftp)

appie21

Active Member
Licensed User
Longtime User
I have a code that do a list import via ftp
That works fine


the file look like these UTF-8

Name,Email, use facebook, use twitter, Hobbes
Alice, [email protected],true, false, cooking and lisen music
Albert, [email protected], true, true, play computer games
...
B4X:
Dim List1 As List
Dim row As  String

List1 = File.ReadList(File.DirInternal, "book.txt")

row = List1.Get(1)

Msgbox( row ,"Rij")

What i now want is that i get only the name and Hobbies info in label from list1

How can i do this?
 

walterf25

Expert
Licensed User
Longtime User
I have a code that do a list import via ftp
That works fine


the file look like these UTF-8

Name,Email, use facebook, use twitter, Hobbes
Alice, [email protected],true, false, cooking and lisen music
Albert, [email protected], true, true, play computer games
...
B4X:
Dim List1 As List
Dim row As  String

List1 = File.ReadList(File.DirInternal, "book.txt")

row = List1.Get(1)

Msgbox( row ,"Rij")

What i now want is that i get only the name and Hobbies info in label from list1

How can i do this?
You can use the Regex function to split the contents for example:

If you have this:
Name,Email, use facebook, use twitter, Hobbes
Alice, [email protected],true, false, cooking and lisen music
Albert, [email protected], true, true, play computer games

you can split everything at the "," (comma) like this:

B4X:
dim readstring as string
dim textread1 as TextReader

textreader1.Initialize(File.OpenInput(File.DirDefaultExternal,"filename.txt")) 'location where file is and name of file
readstring = textreader1.ReadLine 'reads the first line in the file

Do While readstring <> Null  'loops through every line in the file until it finishes.
dim info() as string
info = Regex.Split(",", readstring)   'splits the read line at the "," (comma) it returns an array of 5 elements (zero based)
log("name: " & info(0))
log("hobbies: " & info(4))
readstring = textreader1.ReadLine
loop

Hope this helps.

Walter
 
Last edited:
Upvote 0

appie21

Active Member
Licensed User
Longtime User
It works I have only modify

info = Regex.Split(",") into: info = Regex.Split(",",readstring)

Many thanks!
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
It works I have only modify

info = Regex.Split(",") into: info = Regex.Split(",",readstring)

Many thanks!
Oh sorry, i missed that, but you get the idea.

Glad it worked.

Walter
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
Oh sorry, i missed that, but you get the idea.

Glad it worked.

Walter
A little addon question

how can i add that only get the info of line (row) 2 from the txt file? (without loop)

I have try readstring = textreader1.ReadLine(1) but not work :(
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
A little addon question

how can i add that only get the info of line (row) 2 from the txt file? (without loop)

I have try readstring = textreader1.ReadLine(1) but not work :(

Just read the file two times like this.

B4X:
readstring = textreader1.ReadLine  'this reads the first line
readstring = textreader1.ReadLine 'this reads the second line
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
Hi


I have a little addon question

i have on my layout 3 Labels
and 2 buttons

One of the buttons is next ant the other is Back

What I want is that the labels will be filled with the data from the textreader line 1 and if i press the button again the data from line 2 will be loaded in the labels and so on

And if i press the back button the data from the previos line will be loaded

Ho can I Made this?
B4X:
Dim readstring As String
    Dim textreader1 As TextReader
    Dim info() As String
    textreader1.Initialize(File.OpenInput(File.DirInternal, "book.txt"))
    readstring = textreader1.ReadLine
Do While readstring <> Null
   

    info = Regex.Split(";",readstring)  
    LblReviewName1.Text = info(1)
    LblReviewMening1.Text = info(7)
    LblReviewDate1.Text = info(2)
    readstring = textreader1.ReadLine
   
Loop
 
Upvote 0
Top