OCLOperators split
(Adding message template to the top of the page) |
No edit summary |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
<message>Write the content here to display this box</message> | |||
In OCL, the String split function | In OCL, the String split function expects a char - but OCL defaults single characters to [[Documentation:String|string]]. To solve this, do this: | ||
SomeString.split('X'.toCharArray) | SomeString.split('X'.toCharArray) | ||
This OCL SomeString.split('X') will give you the error: ''31:System.String does not conform to Collection(System.Char)'' | This OCL <code><span class="col-black">'''SomeString.split('X')'''</span></code> will give you the error: ''31:System.String does not conform to Collection(System.Char)'' | ||
An example of creating a <code>Collection(Part1:System.String+Part2:System.String)</code> which is a [[tuple]] that you can iterate to - for example, do search and replace: | An example of creating a <code><span class="col-black">'''Collection(Part1:System.String+Part2:System.String)'''</span></code> which is a [[Documentation:Tuple|tuple]] that you can iterate to - for example, do search and replace: | ||
'A, B; | 'A, B; | ||
X, Y'.Split(';'.toCharArray)->collect(pair | pair.Split(','.toCharArray)->at(1), pair.Split(','.toCharArray)->at(2)) | X, Y'.Split(';'.toCharArray)->collect(pair | pair.Split(','.toCharArray)->at(1), pair.Split(','.toCharArray)->at(2)) | ||
Line 11: | Line 11: | ||
<nowiki> </nowiki> collect(s|Integer.parse(s))-> | <nowiki> </nowiki> collect(s|Integer.parse(s))-> | ||
<nowiki> </nowiki> collect(i|i.toString('x'))->asSeparatedList(<nowiki>''</nowiki>) | <nowiki> </nowiki> collect(i|i.toString('x'))->asSeparatedList(<nowiki>''</nowiki>) | ||
If you want to do the reverse, look at [[OCLOperators asSeparatedList|asSeparatedList]]. | If you want to do the reverse, look at [[Documentation:OCLOperators asSeparatedList|asSeparatedList]]. | ||
{{Edited|July|12| | {{Edited|July|12|2025}} | ||
[[Category:OCL String Operators]] |
Latest revision as of 05:33, 10 February 2025
This page was created by Hans.karlsen@mdriven.net on 2017-05-02. Last edited by Stephanie@mdriven.net 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.