OCLOperators concat
This page was created by Stephanie on 2023-05-03. Last edited by Wikiadmin on 2026-07-29.
You can use concat in OCL when you need to append one string to another, for example when building display text or a message.
Syntax
stringExpression.concat(s)
concat has the following signature:
concat(s : String) : String
It returns a new string that contains the value of self followed by s.
Examples
Append text
The following expression appends ' world' to 'Hello':
'Hello'.concat(' world')
Result:
Hello world
Build a display value
If FirstName contains 'Ada' and LastName contains 'Lovelace', you can create a full name by concatenating the values and the separating space:
self.FirstName.concat(' ').concat(self.LastName)
Result:
Ada Lovelace
Notes
concatappends text to the end of a string. Include any required separator, such as' ',', ', or'-', in the argument.- The operation returns a string; it does not modify the original expression.
- Do not confuse
concat, which operates on strings, with prepend, which adds an object to anOrderedSet. - Use length when you need the number of characters in a string.
