MSI Factory 2.3

TextFile.WriteFromString

TextFile.WriteFromString

This is the first topic This is the last topic  

TextFile.WriteFromString

This is the first topic This is the last topic  

OverviewExamples

TextFile.WriteFromString (

string Filename,

string Text,

boolean Append = false )

Example 1

TextFile.WriteFromString(_TempFolder .. "\\Information.txt", "Blue", false);

Writes the string "Blue" to the file "Information.txt" located in the user's temporary folder. The file's current contents will be overwritten.

Note: _TempFolder is a built-in variable that contains the path to the user's system "Temp" folder.

Example 2

TextFile.WriteFromString(_TempFolder .. "\\Information.txt", "Blue", true);

Appends the string "Blue" to the current contents of the file "Information.txt" located in the user's temporary folder.

Note: _TempFolder is a built-in variable that contains the path to the user's system "Temp" folder.

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

Reads the contents of the file "MyFile.txt" and stores the string in the variable "contents." Every occurrence of the string "Robert" in "contents" is replaced with the string "Adam" and then written back to the text file "MyFile.txt".

See also: Related Actions


Learn More: Indigo Rose Software - MSI Factory - Buy Now - Contact Us