This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Best way to parse a txt table
#1
Hi, 

I have a near by weather station that publish it's data as a txt table. http://grhost.info/kastelokampos/downld02.txt

I would like to get the only the last line of the table in order to use it in my project.
Currently i am using sting.sub (total length - 205 which is the line length) to get the last line and then again string.sub to get each value.

I am sure there must be a more delicate/robust solution but i am stuck so any help would be appreciated.

Thank you in advance
George
Reply
#2
Use this code to split last line data into a table:
Code:
data = ... -- get remote data

lines = data:split('\n')
line = lines[ #lines - 1 ] -- last line
line = line:gsub('%s+', ' ') -- remove multiple spaces
line = line:trim()
line = line:split(' ') -- convert to table

log(line)
Reply
#3
(22.10.2018, 06:21)admin Wrote: Use this code to split last line data into a table:
Code:
data = ... -- get remote data

lines = data:split('\n')
line = lines[ #lines - 1 ] -- last line
line = line:gsub('%s+', ' ') -- remove multiple spaces
line = line:trim()
line = line:split(' ') -- convert to table

log(line)

Nice and clean, thank you!  Smile
Reply


Forum Jump: