Split

In OCL the string split function gets expects a char - but ocl defaults single characters to string. To solve this you can go like 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))
This page was edited 80 days ago on 02/10/2024. What links here