Example 3 -- Read the contents of a text file into a string. contents = TextFile.ReadToString("C:\\MyFile.txt"); -- Check the error code of the last example. error = Application.GetLastError(); -- If an error occurred, display the error message. if (error ~= 0) then Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION); else -- Replace every occurrence of the string "Robert" with the string "Adam". new_contents = String.Replace(contents, "Robert", "Adam", true); -- Write out the modified contents of the text file. TextFile.WriteFromString("C:\\MyFile.txt", new_contents, false); -- Check the error code of the last example. error = Application.GetLastError(); -- If an error occurred, display the error message. if (error ~= 0) then Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION); end end |