Hello IndigoRose,
I use this code to enter data into a text file. It works perfectly fine, I'm wondering if there is a better way when multiple unique strings need to be replaced? Currently I open/read and write for each different string which requires me to open and write to the file multiple times to update the file. Maybe not very efficient. Is there a way to search and replace many different strings with only one open/read and write to the file?
Thanks in advance.
I use this code to enter data into a text file. It works perfectly fine, I'm wondering if there is a better way when multiple unique strings need to be replaced? Currently I open/read and write for each different string which requires me to open and write to the file multiple times to update the file. Maybe not very efficient. Is there a way to search and replace many different strings with only one open/read and write to the file?
Thanks in advance.
Code:
---- Read the contents. contentsXXXXXXX = TextFile.ReadToString(sAppFolder.."\\application.properties"); if (error ~= 0) then Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION); SetupData.WriteToLogFile("ERROR: application.properties" .. Application.GetLastError(), true); else -- Replace string. new_contentsXXXXXXX = String.Replace(contentsXXXXXXX, "abcdef, "uvwxyz"..sAppFolder, true); -- Write new contents. TextFile.WriteFromString(sAppFolder.."\\application.properties", new_contentsXXXXXXX, false); err = Application.GetLastError();if err ~= 0 then sMessage = "###############\r\n" .. "ERROR " .. err .. ": " .. _tblErrorMessages[err] .. "\r\n###############\r\n"; SetupData.WriteToLogFile(sMessage, false);end end
Comment