The Encoding.Default OCL operator converts text to a Blob using the default character encoding of the running .NET implementation; use it when you need the encoded bytes of a string.
Syntax
Encoding.Default.GetBytes(aStringExpression)
| Part | Meaning |
|---|---|
Encoding
|
The static class that provides encoding operations. |
Default
|
Uses the default encoding for the running .NET implementation. |
GetBytes(...)
|
Converts the supplied string expression to encoded bytes. |
| Result | A Blob, which is a byte array containing the numeric byte values that represent the text. |
Example
The following expression encodes the name of the first Customer instance:
Encoding.Default.GetBytes(Customer.allinstances->first.Name)
The expression works as follows:
Customer.allinstancesretrieves the Customer instances.->firstselects the first Customer instance..Namegets that customer's name as text.Encoding.Default.GetBytes(...)translates the characters in the name to their raw byte values.
For example, if the selected customer's name is Anna, the result is a Blob containing the bytes that the current default encoding uses to represent Anna.
Encoding behavior
Encoding.Default uses the default encoding for the environment where the expression runs. That encoding is based on the running .NET implementation's current local encoding. Therefore, the byte values are dependent on that default encoding rather than being fixed by the OCL expression itself.
Use this operator when the receiving operation expects a Blob or byte array. If you need to inspect string size rather than convert text to bytes, see length.
