Reading the last line only of a CVS file from a widget

Bryan

Member
Licensed User
Longtime User
I not sure how to go about this and could use a helpful pointer to get me in the right direction.
I have created a csv file in my main application which I'm able to add and remove lines from it if needed and is displayed in a scrollview table.

I have a Widget that would need to read and write entries into the csv file.
First I need to be able to read the last line in the cvs file. Afterwards I parse specific data from it (the last line).

Question is how do I read the size of the cvs file so I can obtain what the last line is as a integer.
Then I need to read that line into a string variable so I can parse it afterwards.
Then after that is done I would need to append a new line to the csv file.

Can this be done?

Thanks,
Appreciate any help.
Bryan
 

mangojack

Expert
Licensed User
Longtime User
Bryan .. maybe check this thread read random entry from csv

Read the cvs file to a list with StringUtils library, then determine the number of entries.
B4X:
numEntry = List1.Size
myVariable = List1.Get(numEntry -1)

Then just add another line to the list , finally write the list back to file with StringUtils.

hope it helps
Cheer mj
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can also use StringUtils.LoadCSV. It will parse the complete file. You can then add a new row to the list and save it.

However I recommend you to use a SQLite database instead. CSV format is more useful when you need to load some data or save some data. If you need to modify existing data then a real database is much easier to work with.
 
Upvote 0
Top