help with handle the file
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

help with handle the file

Started by suyang99, 07 January, 2004, 10:21:03

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

suyang99

i want to read random line from the multiline file, because i want to search some data in line
how can i do for that ?(  

c h i l l a

--openfile in read mode
local handle = openfile(file,"r")

--read one line

local line = read(handle)

--see if line is there

while line do

--your stuff to do with line

--read next line

line = read(handle)

end

--closefilehandle

closefile(handle)

suyang99

thx a lot
i know this method

i mean like this
i have 10 lines
i think only of to read the 6th

can u hlp me

c h i l l a

#3
as always there are many ways...

but I think the simplest way would be you create a

variable

at the first line = read(handle)

set the varaible to zero

(ex:  var = 0)

and then always count one up each while

var = var + 1

then check if var is your search line

if var == 6 then
 --do what you want with line 6
  break
end

I would call that break cause you don't wanna read any futher.

other soltuion is bit more advanced but faster.
you need to seek all line beginnings once, and insert those seeks in a table, then you have your line positions and call them by seek again.
That what I use in my still now small trivia bot... but that way I have fast access to many lines, and don't have load all questions in a table :). Might post a preview later.

suyang99

thx a lot
u have resolved my big problem

i try to seek all lines in a table but always
  Syntax Error and tell me attempt to concat a nil value
so i don't konw and should how do

SMF spam blocked by CleanTalk