Show in Frame No Frame
Up Previous Next Title Page Index Contents Search

6.4.5 Filename encoding

Within MetaEdit+, all text is effectively Unicode, and you need not think about its encoding. Only when reading and writing to files does the encoding matter. In most cases, external programs will expect files to be in the local platform encoding or code page, and so this is the encoding used by MetaEdit+ by default. Should you wish to change the encoding, e.g. to write an XML file in UTF8 encoding, you can use the encoding parameter:
filename id '.xml' encoding 'utf-8' write
   '<?xml version="1.0" encoding="UTF-8"?>'
   ...
close
The encoding parameter is the first parameter after the clauses whose output makes up the file name, and so comes before md5start. The clauses between encoding and the next parameter of the filename (e.g. md5start, write or read) go to make up the name of an encoding. Most commonly this will just be a literal string like 'utf8' or a variable $enc that was set earlier, but it can of course be any legal sequence of clauses.

Encoders can be names like '437', 'cp437', 'ms_cp_437', 'ms-cp-437', 'ibm437' (all the same thing), 'iso-8859-1', 'iso8859-1', 'iso8859_1' (all the same thing), 'utf8', 'utf-8', 'utf_8', (all the same thing), 'utf-16', 'ucs-2', 'ascii', 'jis', 'shiftjis', 'koi8-r', 'base64', and 'windows-1252'.

By using filename...encoding...read into a variable, then writing the variable with filename...encoding...write...close, you can change the encoding of a file on disk.

Note that encoding does not affect line breaks, which are always read and written in the platform default way.

Show in Frame No Frame
Up Previous Next Title Page Index Contents Search