Breaking up a string in a expression

I want to do some formatting of a text string in a expression.
The string is my current “Window Path”. It is stored in a client tag.

The data stored in the tag would typically be something like:

Based on a user selection (integer) in a IO-field i want to break up this string.
If the user selects “1” then the expression should return: “Plant/”
If the user selects “2” then the expression should return: “Plant/Production/”
If the user selects “3” then the expression should return: “Plant/Production/BioTech/”
… and so on.

I’m struggling to do this in a expression as it seems i can not use a FOR-loop. Do i need to do this operation in a Jython-script?

You could do it for a finite number of custom properties that represent each piece, then an expression that concatenates them.

As far as an elegant way - I think it should be possible. I created a custom property of type DataSet and bound it to the following expression:

split({Root Container.Text Field.text}, '/')

That gets you a dataset with rows corresponding to values between your split character.

I then created a string type Custom Property and bound it to the following:

groupConcat({Root Container.dataset},0, '/')

That reconstructs the entire string. I just need to figure out how to reference the first x number of rows of the DataSet. As a possible feature request, either an optional parameter to the split function for the first x occurrences, or a subset function that works on datasets would be perfect. There is likely currently a way to accomplish this that I am missing.

I’ll work on this more later if nobody provides a complete solution.

Hi Nathan,

I’ve already tried this approach, but as you say the problem is that there doesen’t seem to be easy to return only x number of rows from a dataset.

What I’m actually trying to accomplish is to “dynamize” the alarm path property of the alarm summary based on the displayed window path.
We have several departments in house, and the operator should only be notifyed of alarms from his department (or really the department of the window he is viewing).

For example the alarm path when viewing “Plant/Production/BioTech/OilFactory/Tricanter” should be “Plant/Production/BioTech/” as this is the Biotechnical department.

However, if specifically set as a user parameter (tag); the operator should be able to set another “alarming level”.
1: Alarms for the whole plant
2: Alarms for the plant group (production)
3: Default - alarms for the department (BioTech)
4: Alarms for the line (Oil factory)
5: Alarms for the current picture (Tricanter)

Do you know how many levels deep the max alarm is?

Hi Nathan,

The string would normally (and max) be 5 levels deep.

So you can use the runScript() function to make this work.
Note: I used a text field for the string and a spinner for the number of levels deep.runScript("'/'.join('"+{Root Container.Text Field.text}+"'.split('/', "+{Root Container.Spinner.intValue}+")[:-1])")This will give you every level possible except the actual tag name. You can cap the spinner at 4 (number of levels - 1).

Thank you Robert, just what i was looking for :smiley: