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

You can test whether two String values are equal without regard to upper- and lower-case characters by using compare; this is for developers writing OCL expressions.

Compare two strings without case sensitivity

Use compare with true as its second argument, then test whether the result is 0.

<string 1>.compare(<string 2>, true) = 0

A result of 0 means that the two strings compare as equal when case is ignored.

For example, this expression evaluates to true because the only difference is character case:

'Stockholm'.compare('stockholm', true) = 0

Use the expression in an OCL condition, such as a constraint or a selection predicate, when a value must match a known string regardless of case.

Choose the comparison that matches the requirement

Requirement OCL expression Example result
The values must be exactly equal str1 = str2 'Apple' = 'apple' evaluates to false.
The values must be equal while ignoring case str1.compare(str2, true) = 0 'Apple'.compare('apple', true) = 0 evaluates to true.

Match part of a string

compare tests complete string values. When you need to find text within a value, including a partial match, use sqlLikeCaseInsensitive instead.

For example, the following selects people whose name contains the seek value, regardless of case:

Person.allinstances->select(a|a.Name.sqlLikeCaseInsensitive('%'+vSeekParam+'%'))

See also