Online Help
This is a small action plugin that allows you to read UTF-8 and Unicode encoded text files into a string, as well as save a string as a text file encoded in ANSI (Latin-1), UTF-8 or Unicode format.
Reads the contents of a text file in UTF-8 or Unicode encoding and returns it as a table where each line is an element, in ANSI (Latin-1) encoding.
(string) The full path to the text file.
(string) The encoding of the file to be read. Allowed options are: "iso-8859-1" (no conversion) , "utf-8" and "unicode".
(string) The converted text file as table. You can use Application.GetLastError to determine whether this action failed, and why.
-- read a text file in Unicode encoding
strFile = _TempFolder .. "\\TextFile.txt";
myTable = Unicode.ReadToTable(strFile, "unicode");
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", "Got error code " .. error .. " while converting from Unicode", MB_OK, MB_ICONEXCLAMATION);
else
-- now read each line in the table
for i, text in myTable do
Dialog.Message("info", "line " .. i .. " contains: " .. text, MB_OK);
end
end
Reads the contents of a text file in UTF-8 or Unicode encoding and returns it as a string in ANSI (Latin-1) encoding.
(string) The full path to the text file.
(string) The encoding of the file to be read. Allowed options are: "iso-8859-1" (no conversion) , "utf-8" and "unicode".
(string) The converted text file as string. You can use Application.GetLastError to determine whether this action failed, and why.
-- read a XML file in UTF-8 encoding
strXMLPath = _TempFolder .. "\\utf8File.xml";
convertedXml = Unicode.ReadToString(strXMLPath, "utf-8");
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", "Got error code " .. error .. " while converting from UTF-8", MB_OK, MB_ICONEXCLAMATION);
else
-- everything ok, proceed with XML processing...
XML.SetXML(convertedXml);
end
Writes a table's contents out to a text file. The table should consist of one line of text per table item.
(string) The full path to the text file.
(table) The lines of text to write.
(string) The encoding of the file to be written. Allowed options are: "iso-8859-1", "utf-8" and "unicode".
(nothing) You can use Application.GetLastError to determine whether this action failed, and why.
-- save a table as text file with UTF-8 encoding
Unicode.WriteFromTable(_TempFolder .. "\\utf8File.txt", myTable, "utf-8");
if (error ~= 0) then
Dialog.Message("Error", "Got error code " .. error .. " while converting to UTF-8", MB_OK, MB_ICONEXCLAMATION);
end
Writes a string of text to a new file in a specific character encoding.
(string) The full path to the text file.
(string) The string of text to write.
(string) The encoding of the file to be written. Allowed options are: "iso-8859-1", "utf-8" and "unicode".
(nothing) You can use Application.GetLastError to determine whether this action failed, and why.
-- save a string as text file with Unicode encoding
Unicode.WriteFromString(_TempFolder .. "\\unicodeFile.txt", myString, "unicode");
if (error ~= 0) then
Dialog.Message("Error", "Got error code " .. error .. " while converting to Unicode", MB_OK, MB_ICONEXCLAMATION);
end
12030 - Failed to start Unicode Actions plugin.
12031 - Conversion failed.
12032 - File not found.
12033 - Could not save file.
12034 - Internal error.
Ulrich Peters
upeters@mindquake.com.br
Plugin is copyright © 2009 MindQuake Serviços de Informática Ltda.
Copyright © 2008-2009 MindQuake Serviços de Informática Ltda.
Todos os direitos reservados.