Lua - Insert or Delete String in txt file -
Assume that I have a .txt file that has a string I. How can I remove some characters, or both of them Can I include others between? Example: .txt file contains "HelloWald" and I want to insert a comma after "Hello" and there is a place after that. I just know how to write from the beginning and attach a file
local file = io.open ("example.txt", "w") file: write ("example") file You have to break it down in different steps .close ()
You have to break it down in different steps.
The following example is "Hello, World"
- - Read the file - Local f = io.open ("example.txt", "r") with " Change the "HelloWald") local content = f: read ("* all") f: close () - - edit string - content = string.gsub (content, "hello", "hello,") - - Type it out - local f = io.open ("example.txt", "w") f: write (content) f: close ()
Of course you need to add an error - test, etc.
Comments
Post a Comment