Method

# EncodeHex

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

## Description

Returns the passed `String</api/data_types/string>` as hex values with the option of separating each hex value in the result with a space.

## Usage

``` xojo
result = EncodeHex(s, Optional insertSpaces = False)
```

| Part         | Type                               | Description                                                                                                                          |
|--------------|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
| result       | `String</api/data_types/string>`   | The passed string as a series of Hex values.                                                                                         |
| s            | `String</api/data_types/string>`   | The string to be encoded into hex.                                                                                                   |
| insertSpaces | `Boolean</api/data_types/boolean>` | If `True</api/language/true>`, each hex value in *result* will be separated by a space. The default is `False</api/language/false>`. |

## Notes

Hexadecimal encoded strings are byte-based instead of character-based, i.e. they ignore `text encodings</api/text/encoding_text/textencoding>`. For example, the string "Xojo™" is 5 characters long but, as it uses UTF-8 as encoding, it is 7 bytes long (the ™ character uses 3 bytes in UTF-8). You should keep that in mind when using <span class="title-ref">EncodeHex</span> and `DecodeHex</api/text/encoding_text/decodehex>`.

## Sample code

Generate a hex string without spaces:

``` xojo
Var s As String
s = EncodeHex("The cake is a lie.", False)
' s is "5468652063616B652069732061206C69652E"
```

## Compatibility

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

<div class="seealso">

`DecodeHex</api/text/encoding_text/decodehex>`, `Hex</api/text/hex>` functions.

</div>
