Module

# Encodings

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Returns the specified `TextEncoding</api/text/encoding_text/textencoding>`.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                 | Parameters                                         | Returns                                              | Shared |
|--------------------------------------|----------------------------------------------------|------------------------------------------------------|--------|
| `Count<encodings.count>`             |                                                    | `Integer</api/data_types/integer>`                   |        |
| `FromName<encodings.fromname>`       | name As `String</api/data_types/string>`           | `TextEncoding</api/text/encoding_text/textencoding>` |        |
| `GetFromCode<encodings.getfromcode>` | encodingCode As `Integer</api/data_types/integer>` | `TextEncoding</api/text/encoding_text/textencoding>` |        |
| `Item<encodings.item>`               | index As `Integer</api/data_types/integer>`        | `TextEncoding</api/text/encoding_text/textencoding>` |        |

## Usage

You can use the following syntax to easily get any `TextEncoding</api/text/encoding_text/textencoding>` object:

``` xojo
result = Encodings.EncodingName
```

where *EncodingName* is one of the following

| Encoding Names     |
|--------------------|
| ASCII              |
| DOSArabic          |
| DOSBalticRim       |
| DOSCanadianFrench  |
| DOSChineseSimplif  |
| DOSChineseTrad     |
| DOSCyrillic        |
| DOSGreek           |
| DOSGreek1          |
| DOSGreek2          |
| DOSHebrew          |
| DOSIcelandic       |
| DOSJapanese        |
| DOSKorean          |
| DOSLatin1          |
| DOSLatin2          |
| DOSLatinUS         |
| DOSNordic          |
| DOSPortuguese      |
| DOSRussian         |
| DOSThai            |
| DOSTurkish         |
| ISOLatin1          |
| ISOLatin2          |
| ISOLatin3          |
| ISOLatin4          |
| ISOLatin5          |
| ISOLatin6          |
| ISOLatin7          |
| ISOLatin8          |
| ISOLatin9          |
| ISOLatinArabic     |
| ISOLatinCyrillic   |
| ISOLatinGreek      |
| ISOLatinHebrew     |
| KOI8_R             |
| MacArabic          |
| MacArmenian        |
| MacBengali         |
| MacBurmese         |
| MacCeltic          |
| MacCentralEurRoman |
| MacChineseSimp     |
| MacChineseTrad     |
| MacCroatian        |
| MacCyrillic        |
| MacDevanagari      |
| MacDingbats        |
| MacEthiopic        |
| MacExtArabic       |
| MacGaelic          |
| MacGeorgian        |
| MacGreek           |
| MacGujarati        |
| MacGurmukhi        |
| MacHebrew          |
| MacIcelandic       |
| MacJapanese        |
| MacKannada         |
| MacKhmer           |
| MacKorean          |
| MacLaotian         |
| MacMalayalam       |
| MacMongolian       |
| MacOriya           |
| MacRoman           |
| MacRomanian        |
| MacRomanLatin1     |
| MacSinhalese       |
| MacSymbol          |
| MacTamil           |
| MacTelugu          |
| MacThai            |
| MacTibetan         |
| MacTurkish         |
| MacVietnamese      |
| ShiftJIS           |
| SystemDefault      |
| UTF16              |
| UTF16BE            |
| UTF16LE            |
| UTF32              |
| UTF32BE            |
| UTF32LE            |
| UTF8               |
| WindowsANSI        |
| WindowsArabic      |
| WindowsBalticRim   |
| WindowsCyrillic    |
| WindowsGreek       |
| WindowsHebrew      |
| WindowsKoreanJohab |
| WindowsLatin1      |
| WindowsLatin2      |
| WindowsLatin5      |
| WindowsVietnamese  |

## Method descriptions

<div id="encodings.count">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Encodings.Count

**Count** As `Integer</api/data_types/integer>`

> Returns the number of <span class="title-ref">Encodings</span> in the built-in list of <span class="title-ref">Encodings</span>.

<div id="encodings.fromname">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Encodings.FromName

**FromName**(name As `String</api/data_types/string>`) As `TextEncoding</api/text/encoding_text/textencoding>`

> Returns the `TextEncoding</api/text/encoding_text/textencoding>` for the *name* passed.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This method is supported for Android projects only.
>
> </div>

<div id="encodings.getfromcode">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Encodings.GetFromCode

**GetFromCode**(encodingCode As `Integer</api/data_types/integer>`) As `TextEncoding</api/text/encoding_text/textencoding>`

> Returns the `TextEncoding</api/text/encoding_text/textencoding>` object corresponding to the *encodingCode* passed.
>
> Codes can be obtained via `declares</api/language/declare>` or the `Code<textencoding.code>` method of `TextEncoding</api/text/encoding_text/textencoding>` objects.

<div id="encodings.item">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Encodings.Item

**Item**(index As `Integer</api/data_types/integer>`) As `TextEncoding</api/text/encoding_text/textencoding>`

> Returns the specified element of the list of <span class="title-ref">Encodings</span> by its *index*. *index* is zero-based.

## Notes

The <span class="title-ref">Encodings</span> module makes it easy to obtain a specified `TextEncoding</api/text/encoding_text/textencoding>`. Any text encoding can be obtained via the <span class="title-ref">Encodings</span> module. Some of the most useful are UTF8, UTF16, ASCII, MacRoman, MacJapanese, and WindowsLatin1. It includes the UTF16BE (big endian) and UTF16LE (little endian) <span class="title-ref">Encodings</span> 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.

## Sample code

Use the Chr method of the `TextEncoding</api/text/encoding_text/textencoding>` class to get a specific character in any encoding scheme. You use the <span class="title-ref">Encodings</span> function to first get the desired encoding. For example:

``` xojo
Var s As String
s = Encodings.UTF8.Chr(169)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

When you read a string that was created outside your app, you should specify its encoding so that the byte string can be interpreted correctly. Use the <span class="title-ref">Encodings</span> function to get the encoding and pass it to the Encoding property of the `TextInputStream</api/files/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.

``` xojo
Var f As FolderItem = FolderItem.ShowOpenFileDialog(FileTypes1.Text)

If f <> Nil then
  Var t As TextInputStream = 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.

To get an encoding by its String name, you can use a method like this:

``` xojo
Public Function EncodingFromName(value As String) as TextEncoding
  Var enc As TextEncoding

  For i As Integer = 0 To Encodings.Count - 1
    enc = Encodings.Item(i)
    If enc.internetName = value Then
      Return enc
    End If
  Next

  Raise New InvalidArgumentException("Encoding for name is not known.")
End Function
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`TextConverter</api/text/encoding_text/textconverter>`, `TextEncoding</api/text/encoding_text/textencoding>`, `TextInputStream</api/files/textinputstream>` classes; `DefineEncoding</api/text/encoding_text/defineencoding>`, `ConvertEncoding</api/text/encoding_text/convertencoding>`, `GetInternetTextEncoding</api/text/encoding_text/getinternettextencoding>`, `Encoding</api/text/encoding_text/encoding>` functions.

</div>
