Android Question Arranging the .txt file

Izmirov.Yaminovich

Member
Licensed User
Longtime User
Hi,

I have this saved .txt file in my app where it will record down the datas when I click save. However, the .txt file shows it in an arrangement like this:

0
1
2
3

I would like it to be like this:
0 1 2 3

It would be better if I can add in coma in between as well. How do I arrange it that way?
 

ilan

Expert
Licensed User
Longtime User
B4X:
Sub Save_click
  Dim str As String = "0,1,2,3"
   
  Dim writer As TextWriter
  writer.Initialize(File.OpenOutput(File.DirApp,"data.txt",True))
  writer.WriteLine(str)
  writer.Close
End Sub

and if you want to save the content from views then like this

B4X:
Sub Save_click
  Dim str As String = Edittext1.text & "," & Edittext2.text & "," & Lat.Text" & "," & Lon.Text & "," & Time.Text
   
  Dim writer As TextWriter
  writer.Initialize(File.OpenOutput(File.DirApp,"data.txt",True))
  writer.WriteLine(str)
  writer.Close
End Sub

NOTE that i wrote "TRUE" in the Append argument since you want to attach another line to the text file and not rewrite the textfile
 
Upvote 0

ilan

Expert
Licensed User
Longtime User

to get values from that file i will need to split the list item correct?

i cannot handle it like an excel file where i have rows and columns?

is there a way to save everything to a csv file and load it to a table that is not a VIEW so i can handle like an excel table (columns, rows)? (except of sql)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
i cannot handle it like an excel file where i have rows and columns?

sure, split on crlf and you have your rows.

split the row on comma and you have the cell/column.

if you need to do a lot of operations you might want to dump the data to a multi dimensional array
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
sure, split on crlf and you have your rows.

split the row on comma and you have the cell/column.
i dont want to split everytime the string i would like to hold all data in a virtual table
where i can always say label1.text = table(x,y)

a 2d array could be a solution but is there a simple way to save/load a 2d array?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i dont want to split everytime the string i would like to hold all data in a virtual table
where i can always say label1.text = table(x,y)

a 2d array could be a solution but is there a simple way to save/load a 2d array?

i guess a 2d array is not a solution here since i need to add new rows to it (like in a table)
but anyway i think it is better to open a new thread for this question
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
forum search will give you a lot of sqlite stuff. it's maybe overkill for what you want to do tho.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…