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

Searching for keywords in a file

Started by ComputerCraftFan11, 08 May 2012 - 02:55 AM
ComputerCraftFan11 #1
Posted 08 May 2012 - 04:55 AM
(second time posting this year in ask a pro :)/>/>)

If i'm making a program and it contains code like:

echo "Hello world!"
pause

How can I split up the program and replace echo "Hello world!" with:

print("Hello world!")
And pause with:

print("Press any key to continue.")
os.pullEvent("key")

Like this:

file = fs.open("example", "r")
code = file.readAll()
file.close()
--search for "pause" and "echo" in "code"
execute = fs.open("executer", "w")
execute.write(code)
execute.close()
shell.run("executer")
fs.delete("executer")
libraryaddict #2
Posted 08 May 2012 - 04:59 AM
http://lua-users.org/wiki/StringLibraryTutorial

Look for string.sub and string.find