🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators UTF7
This page was created by Lars.olofsson on 2023-05-03. Last edited by Wikiadmin on 2026-07-29.

You can use Encoding.UTF7 in OCL when you need to encode a string as UTF-7 bytes or decode UTF-7 bytes back to a string.

UTF-7 encoding

UTF-7 (Unicode Transformation Format 7-bit) is a variable-length character encoding that represents Unicode text using 7-bit-safe characters. UTF-7 leaves ordinary ASCII characters, such as letters and numbers, unchanged. It represents other characters in an encoded section that starts with + and ends with -.

For example, the UTF-7 representation of é contains +AOk-. A value such as Café therefore retains the ASCII characters Caf and encodes the non-ASCII character é.

Encode a string to UTF-7 bytes

Use Encoding.UTF7.GetBytes(string) to convert a string to a byte array.

Encoding.UTF7.GetBytes('Café')

The result is a byte array containing the UTF-7 encoded value. Use this form when the receiving operation expects bytes rather than a string.

Decode UTF-7 bytes to a string

Use Encoding.UTF7.GetString(bytearray) to convert a UTF-7 byte array to text.

Encoding.UTF7.GetString(bytearray)

For example, if utf7Bytes contains UTF-7 bytes for Café, the expression below returns Café.

Encoding.UTF7.GetString(utf7Bytes)

Choose the same encoding for both directions

Encoding and decoding must use the same encoding. If you create bytes with Encoding.UTF7.GetBytes(...), read those bytes with Encoding.UTF7.GetString(...).

Task OCL expression
Convert text to UTF-7 bytes Encoding.UTF7.GetBytes('Café')
Convert UTF-7 bytes to text Encoding.UTF7.GetString(bytearray)

For the available encoding operations and equivalent examples using other encodings, see Documentation:Encoding.

See also