Encodings

From Xojo Documentation

Revision as of 19:09, 19 November 2009 by 10.0.1.5 (talk) (Examples)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Description

Returns the specified TextEncoding.


Syntax

result=Encodings.EncodingsName

Part Type Description
result TextEncoding The text encoding specified by EncodingsName.
EncodingsName String The name of a TextEncoding. Use the Code Editor's AutoComplete feature to show all possible values of EndodingsName.


Methods

Name Parameters Return Type Description
Count
Introduced 2008r2
Integer Returns the number of encodings in the built-in list of encodings.
Item
Introduced 2008r2
Index as Integer TextEncoding Returns the specified element of the list of encodings by its index. Index is zero-based.


Notes

The Encodings module makes it easy to obtain a specified TextEncoding. Any text encoding can be obtained via the Encodings module. Some of the most useful are UTF8, UTF16, ASCII, MacRoman, MacJapanese, and WindowsLatin1. It includes the UTF16BE (big endian) and UTF16LE (little endian) encodings for reading and writing encoded text to files on computers that require either big or little endianness.

Use the Autocomplete feature of the Code Editor to view the complete list.


Examples

Use the Chr method of the TextEncoding class to get a specific character in any encoding scheme. You use the Encodings module to first get the desired encoding. For example:

Dim s as String
s=Encodings.UTF8.Chr(169)


When you read a string that was created outside REALbasic, you should specify its encoding so that REALbasic can interpret the byte string correctly. Use the Encodings module to get the encoding and pass it to the Encoding property of the TextInputStream class. This example specifies the MacCentralEurRoman encoding.

The Text file type was defined in the File Type Sets editor as one of the common file types.

f=GetOpenFolderItem(FileTypes1.Text)
If f <> Nil then
t=TextInputStream.Open(f)
t.Encoding=Encodings.MacCentralEurRoman
TextField1.text=t.ReadAll
t.Close
End if

You can also specify the encoding of text using the optional parameter of the Read, ReadLine, or ReadAll methods.


See Also

TextConverterTextEncoding, TextInputStream classes; DefineEncoding, ConvertEncoding, Encoding functions.