<div class="meta" robots="noindex">

</div>

Class

# Xojo.Core.TextEncoding

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

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2020r2. Please use `TextEncoding</api/text/encoding_text/textencoding>` as a replacement.

</div>

## Description

An encoding represents a way of converting text to and from raw bytes. Encodings are created from IANA character set names or the shared properties for the very common encodings. Use this class to convert Text to specific encodings and to convert Text to and from MemoryBlocks.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                                          | Type                                                 | Read-Only | Shared |
|---------------------------------------------------------------|------------------------------------------------------|-----------|--------|
| `ASCII<xojo.core.textencoding.ascii>`                         | `TextEncoding</api/text/encoding_text/textencoding>` | ✓         |        |
| `IANAName<xojo.core.textencoding.iananame>`                   | `Text</api/deprecated/text>`                         | ✓         |        |
| `UTF16<xojo.core.textencoding.utf16>`                         | `TextEncoding</api/text/encoding_text/textencoding>` | ✓         |        |
| `UTF16BigEndian<xojo.core.textencoding.utf16bigendian>`       | `TextEncoding</api/text/encoding_text/textencoding>` | ✓         |        |
| `UTF16LittleEndian<xojo.core.textencoding.utf16littleendian>` | `TextEncoding</api/text/encoding_text/textencoding>` | ✓         |        |
| `UTF32<xojo.core.textencoding.utf32>`                         | `TextEncoding</api/text/encoding_text/textencoding>` | ✓         |        |
| `UTF32BigEndian<xojo.core.textencoding.utf32bigendian>`       | `TextEncoding</api/text/encoding_text/textencoding>` | ✓         |        |
| `UTF32LittleEndian<xojo.core.textencoding.utf32littleendian>` | `TextEncoding</api/text/encoding_text/textencoding>` | ✓         |        |
| `UTF8<xojo.core.textencoding.utf8>`                           | `TextEncoding</api/text/encoding_text/textencoding>` | ✓         |        |
| `Windows1252<xojo.core.textencoding.windows1252>`             | `TextEncoding</api/text/encoding_text/textencoding>` | ✓         |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                          | Parameters                                                                                                                        | Returns                                              | Shared |
|---------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------|--------|
| `ConvertDataToText<xojo.core.textencoding.convertdatatotext>` | data As `MemoryBlock</api/language/memoryblock>`, allowLossy As `Boolean</api/data_types/boolean>` = `False</api/language/false>` | `String</api/data_types/string>`                     |        |
| `ConvertTextToData<xojo.core.textencoding.converttexttodata>` | value As `String</api/data_types/string>`, allowLossy As `Boolean</api/data_types/boolean>` = `False</api/language/false>`        | `MemoryBlock</api/language/memoryblock>`             |        |
| `FromIANAName<xojo.core.textencoding.fromiananame>`           | name As `String</api/data_types/string>`                                                                                          | `TextEncoding</api/text/encoding_text/textencoding>` |        |

## Property descriptions

<div id="xojo.core.textencoding.ascii">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.ASCII

**ASCII** As `TextEncoding</api/text/encoding_text/textencoding>`

Returns the ASCII text encoding.

This property is read-only.

<div id="xojo.core.textencoding.iananame">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.IANAName

**IANAName** As `Text</api/deprecated/text>`

The encoding's name as specified in [IANA's Character Sets](http://www.iana.org/assignments/character-sets/character-sets.xhtml) document.

This property is read-only.

<div id="xojo.core.textencoding.utf16">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.UTF16

**UTF16** As `TextEncoding</api/text/encoding_text/textencoding>`

Returns the UTF-16 text encoding.

This property is read-only.

<div id="xojo.core.textencoding.utf16bigendian">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.UTF16BigEndian

**UTF16BigEndian** As `TextEncoding</api/text/encoding_text/textencoding>`

Returns the UTF-16 text encoding with each code unit stored as big endian.

This property is read-only.

<div id="xojo.core.textencoding.utf16littleendian">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.UTF16LittleEndian

**UTF16LittleEndian** As `TextEncoding</api/text/encoding_text/textencoding>`

Returns the UTF-16 text encoding with each code unit stored as little endian.

This property is read-only.

<div id="xojo.core.textencoding.utf32">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.UTF32

**UTF32** As `TextEncoding</api/text/encoding_text/textencoding>`

Returns the UTF-32 text encoding. This is an alias for either UTF32LittleEndian or UTF32BigEndian depending on the endianness of the target.

This property is read-only.

<div id="xojo.core.textencoding.utf32bigendian">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.UTF32BigEndian

**UTF32BigEndian** As `TextEncoding</api/text/encoding_text/textencoding>`

Returns the UTF-32 text encoding with each code unit stored as big endian.

This property is read-only.

<div id="xojo.core.textencoding.utf32littleendian">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.UTF32LittleEndian

**UTF32LittleEndian** As `TextEncoding</api/text/encoding_text/textencoding>`

Returns the UTF-32 text encoding with each code unit stored as little endian.

This property is read-only.

<div id="xojo.core.textencoding.utf8">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.UTF8

**UTF8** As `TextEncoding</api/text/encoding_text/textencoding>`

Returns the UTF-8 text encoding.

This property is read-only.

<div id="xojo.core.textencoding.windows1252">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.Windows1252

**Windows1252** As `TextEncoding</api/text/encoding_text/textencoding>`

Returns the Windows 1252 (ISO Latin-1) text encoding.

This property is read-only.

## Method descriptions

<div id="xojo.core.textencoding.convertdatatotext">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.ConvertDataToText

**ConvertDataToText**(data As `MemoryBlock</api/language/memoryblock>`, allowLossy As `Boolean</api/data_types/boolean>` = `False</api/language/false>`) As `String</api/data_types/string>`

Converts a chunk of data in a MemoryBlock to Text.

Converts a chunk of data to Text. If the data is not valid for this encoding (e.g. overlong UTF-8 sequences), an exception is raised. The allowLossy parameter can be used to override this behavior. If it is True, any invalid input is replaced with the Unicode replacement character (U+FFFD).

<div class="warning">

<div class="title">

Warning

</div>

A `NilObjectException</api/exceptions/nilobjectexception>` will be raised if data is Nil.

</div>

<div class="warning">

<div class="title">

Warning

</div>

A `RuntimeException</api/exceptions/runtimeexception>` will be raised if data is not valid for the encoding and allowLossy is False or if data has an unknown size.

</div>

This code takes data that came in on a MemoryBlock from an `Xojo.Net.HTTPSocket</api/deprecated/xojo.net.httpsocket>` event and converts it to UTF8 Text:

``` xojo
Var jsonData As Text = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(content)
```

<div id="xojo.core.textencoding.converttexttodata">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.ConvertTextToData

**ConvertTextToData**(value As `String</api/data_types/string>`, allowLossy As `Boolean</api/data_types/boolean>` = `False</api/language/false>`) As `MemoryBlock</api/language/memoryblock>`

Converts a text value to bytes in a MemoryBlock.

If the value cannot be represented accurately in this encoding, an exception is raised. The allowLossy parameter can be used to override this behavior. If it is True, any characters that cannot be represented are replaced with a question mark. For example, Emoji is not representable in the ASCII encoding.

If the encoding is UTF-16 or UTF-32, the resulting data will begin with a byte order mark. If the byte order mark is not desired, the encoding should specify an explicit big endian or little endian (e.g. using UTF32LittleEndian).

<div class="warning">

<div class="title">

Warning

</div>

A `RuntimeException</api/exceptions/runtimeexception>` will be raised if value cannot be represented accurately in the encoding and allowLossy is False.

</div>

Convert text to UTF-8 data:

``` xojo
Var t As Text = "Jåbberwøcky"
Var utf8Data As Xojo.Core.MemoryBlock
utf8Data = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(t)
```

<div id="xojo.core.textencoding.fromiananame">

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

</div>

<div class="rst-class">

forsearch

</div>

Xojo.Core.TextEncoding.FromIANAName

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

Returns an encoding given its IANA name as specified in [IANA's Character Sets](http://www.iana.org/assignments/character-sets/character-sets.xhtml) document.

Gets the US ASCII encoding from its name:

``` xojo
Var encoding As Xojo.Core.TextEncoding  
encoding = Xojo.Core.TextEncoding.FromIANAName("US-ASCII")
```

## Compatibility

All project types on all supported operating systems.

## See also

`Object</api/data_types/additional_types/object>` parent class; `Locale</api/os/locale>`, `MemoryBlock</api/language/memoryblock>`, `TextInputStream</api/files/textinputstream>`, `TextOutputStream</api/files/textoutputstream>` classes; `String</api/data_types/string>` data type

`TextEncoding</api/text/encoding_text/textencoding>` class; `Encodings</api/text/encoding_text/encodings>` module
