🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators ASCII
Created by Lars.olofsson on 2019-10-31 · Last edited by Colline.ssali on 2025-12-23.

The OCL Operator ASCII is an operator of the static class Encoding.

The ascii() operator in OCL is used to return the ASCII numeric value of a character in a string. It is typically applied to a single-character string and converts that character into its corresponding integer code based on the ASCII table. This operator is useful in scenarios where you need to compare characters numerically, perform validations, implement custom sorting logic, or analyze text at a low level. For example, using ascii() allows you to distinguish between uppercase and lowercase letters or check whether a character falls within a specific range, such as digits or alphabetic characters.

Example:

'A'.ascii()

Result:65


Assume the Department class has an attribute called Code, which is a string. The ascii() operator can be used to evaluate or validate the characters in this attribute. For example, if you want to check whether the first character of the department code is an uppercase letter, you can extract that character and convert it to its ASCII value.

self.Code.substring(1,1).ascii() >= 65 and self.Code.substring(1,1).ascii() <= 90

This expression returns true if the first character of the department’s code is between A (65) and Z (90) in the ASCII table, ensuring that the code starts with an uppercase letter.