OCLOperators split
This page was created by Hans.karlsen on 2017-05-02. Last edited by Stephanie on 2025-02-10.
In OCL, the String split function expects a char - but OCL defaults single characters to string. To solve this, do this:
SomeString.split('X'.toCharArray)
This OCL SomeString.split('X')
will give you the error: 31:System.String does not conform to Collection(System.Char)
An example of creating a Collection(Part1:System.String+Part2:System.String)
which is a tuple that you can iterate to - for example, do search and replace:
'A, B; X, Y'.Split(';'.toCharArray)->collect(pair | pair.Split(','.toCharArray)->at(1), pair.Split(','.toCharArray)->at(2))
RGB := '241, 55, 45'; '#' + RGB.split(','.toCharArray)-> collect(s|Integer.parse(s))-> collect(i|i.toString('x'))->asSeparatedList('')
If you want to do the reverse, look at asSeparatedList.