MSI Factory 2.3

TextFile.ReadToString

TextFile.ReadToString

This is the first topic This is the last topic  

TextFile.ReadToString

This is the first topic This is the last topic  

OverviewExamples

string TextFile.ReadToString (

string Filename )

Example 1

text_contents = TextFile.ReadToString(_SourceDrive .. "\\Information.txt");

Reads the contents of the file "Information.txt" and stores the string in the variable text_contents.

Example 2

-- 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