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

You can use the ascii() operator of the Encoding static class when you need the numeric ASCII value of a character while writing OCL expressions.

What ascii() returns

The ascii() operator converts a character to its ASCII (American Standard Code for Information Interchange) numeric value. Use it with a single-character string when you need to compare that character by its numeric code.

For example, the ASCII value for A is 65. The values for uppercase English letters run from 65 (A) through 90 (Z).

Character ASCII value
A 65
Z 90
a 97
z 122
0 48
9 57

When to use it

Use ascii() when a rule depends on an ASCII range rather than on a literal character comparison. Typical uses include:

  • Checking whether a character is an uppercase English letter.
  • Checking whether a character is a digit.
  • Distinguishing uppercase from lowercase characters.
  • Applying a numeric ordering rule to ASCII characters.

Example: validate the first character of a department code

Assume that Department has a string attribute named Code. First obtain the first character of Code, then apply ascii() to that character.

The validation is true when the resulting value is between 65 and 90, inclusive. For example:

  • A code beginning with A, such as Accounts, passes because A is 65.
  • A code beginning with Z, such as Zonal, passes because Z is 90.
  • A code beginning with a, such as accounts, does not pass because a is 97.
  • A code beginning with 1, such as 123, does not pass because 1 is 49.

Before evaluating a first character, make sure that the code contains at least one character. Use size() to test the string length.

Limits and considerations

ASCII covers the basic Latin alphabet, digits, and selected punctuation and control characters. Do not use ASCII ranges as a general test for letters in names or codes that can contain non-ASCII characters such as é, ñ, or emoji.

Use the OCL editor to inspect the operators available for the applicable type and to confirm the expression syntax in your MDriven version. For general operator discovery, see Documentation:OCL General Operators.

Related encoding operations

ascii() returns a numeric character value. It does not convert an entire string to a byte array. For byte conversion, see GetBytes. For UTF-7 encoding, see UTF7.

See also