Jump to content




Searching for keywords in a file


  • You cannot reply to this topic
1 reply to this topic

#1 ComputerCraftFan11

  • Members
  • 771 posts
  • LocationHawaii

Posted 08 May 2012 - 03: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")


#2 libraryaddict

  • New Members
  • 195 posts

Posted 08 May 2012 - 03:59 AM

http://lua-users.org...LibraryTutorial

Look for string.sub and string.find





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users