This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
kotorone1's profile picture

[question] Searching through a file to find and change on line

Started by kotorone1, 05 August 2012 - 04:20 AM
kotorone1 #1
Posted 05 August 2012 - 06:20 AM
Hello,

I am trying to store data in a file in the format

name:password:integer

is it possible to write a function that searches through that file, finds that specific line, and can either copy it or change the line?

or is it easier to

myTable = {}
myTable[1] = textutils.serialize({name,password,integer})
myTable[2] = textutils.serialize({name,password,integer})
myTable[3] = textutils.serialize({name,password,integer})
et cetera, and search thru the table and look for the needed line, deserialize it and return a result?

Thanks,
~Matt
Ponder #2
Posted 05 August 2012 - 01:15 PM
There are already function to do that in the Lua String API. They use Regular Expression, it is a bit tricky if you are not familiar with them, but you should check this out.
Noodle #3
Posted 06 August 2012 - 11:16 AM
You could list the lines of a file then edit the single lines using string.sub
Something like that.